python - 形成文件路径时的错误
问题描述
start() 函数连续运行,直到被强制停止。
import time
import datetime
import math
import image_processing
images_folder = "images/"
folder_name = images_folder + str(datetime.datetime.now().date())
screen_data = image_processing.getScreenData()
stack_collection = image_processing.getStackImages()
def start():
for item in screen_data:
image_name = str(math.floor(time.time()))
image_path = folder_name + "/" + str(item['screen_area']) + "/" + image_name + ".png"
image_processing.imaging(item['x_coordinate'], item['y_coordinate'], item['width'], item['height'],
image_path, item['screen_area'])
问题是 - 有时(不经常)一些图像保存在/images
文件夹中,而不是完整路径。为什么会发生这种情况?
解决方案
要构建目录路径,您始终可以使用该os
库:
import os
os.path.join(folder_name , str(item['screen_area']) , image_name + ".png")
推荐阅读
- direct3d - D3D 从计算着色器写入纹理
- python - 使用python从列表中获取字符串
- compilation - 不鼓励在构建 openssl 时使用 no-asm 选项吗?
- c++ - 在钳位信号 .0-1 DSP 上使用 pow() 或类似的可调节曲线的 C++ 高效输入控制?
- scrapy - 我如何使用带有scrapy的旋转代理?
- python - 在 Python 中实现 LinkedList - leetcode 错了吗?
- html - 如何编辑基础站点框架的scss变量并重新编译CSS?
- javascript - 如何在同一行中获取嵌入字段标题和值
- php - 在 Foreach 语句 (PHP) 中的 X 数量结果后进行换行
- python - 取款系统在 OnetoOneField 中出现 IntegrityError。第一次一切正常然后出错