无法识别不存在的文件
我使用此代码(类的一部分)遇到一个奇怪的错误:
from sys import path as workingDIR
from os import system, path
image = '' # some jpeg image data
keep = 0
DIR = workingDIR[0] + '\\image'
if path.isfile(DIR + '.jpeg'): # adding numbers to end of file name like how windows prevents multiple files having the same name
x = 2
while path.isfile(DIR + ' (' + str(x) + ').jpeg'):
x += 1
DIR += ' (' + str(x) + ')'
DIR += '.jpeg'
f = open(DIR, 'w+b')
f.write(image)
f.close()
system(DIR)
system('pause')
if not(keep):
remove(DIR)
cmd 告诉我 '...\image' 未被识别为内部或外部命令、可操作程序或批处理文件。
(忽略 ...
),这没有意义,因为 DIR 已更改为 ...\image.jpeg
但它正在获取 image< /代码>。我在这里做错了什么?
im getting a weird error using this code (part of a class):
from sys import path as workingDIR
from os import system, path
image = '' # some jpeg image data
keep = 0
DIR = workingDIR[0] + '\\image'
if path.isfile(DIR + '.jpeg'): # adding numbers to end of file name like how windows prevents multiple files having the same name
x = 2
while path.isfile(DIR + ' (' + str(x) + ').jpeg'):
x += 1
DIR += ' (' + str(x) + ')'
DIR += '.jpeg'
f = open(DIR, 'w+b')
f.write(image)
f.close()
system(DIR)
system('pause')
if not(keep):
remove(DIR)
cmd is telling me '...\image' is not recognized as an internal or external command, operable program or batch file.
(ignore the ...
), which doesnt make sense, because DIR has already been changed to ...\image.jpeg
and yet it is getting image
. what am i doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
图像文件名中有多余的空格 - “..\image (1).jpeg”
因此,当您调用 system(DIR) 时,“..\image”成为命令,“(1).jpeg”是第一个参数。
You have an extra white space in the image filename - "..\image (1).jpeg"
so when you call system(DIR), "..\image" becomes the command and "(1).jpeg" is the first argument.