我使用此代码(类的一部分)得到一个奇怪的错误:
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' is not recognized as an internal or external command, operable program or batch file.
(忽略...
),这没有任何意义,因为DIR已经更改为...\image.jpeg
但它已经获得image
。我在这做错了什么?
答案 0 :(得分:3)
图像文件名中有一个额外的空格 - “.. \ image(1).jpeg”
所以当你调用system(DIR)时,“.. \ image”成为命令,“(1).jpeg”是第一个参数。