我正在编写一些代码,它将通过一个文件,将其作为临时文件进行编辑,然后将临时文件复制到新文件上以便进行编辑。但是,当使用shutil 的move 方法时,我不断收到此错误:
IOError:[Errno 22] 无效参数
我试过使用 copy、copy2 和 copyfile。这是代码的副本:
def writePPS(seekValue,newData):
PPSFiles = findPPS("/pps")
for file in PPSFiles:
#create a temp file
holder,temp = mkstemp(".pps")
print holder, temp
pps = open(file,"r+")
newpps = open(temp,"w")
info = pps.readlines()
#parse through the pps file and find seekvalue, replace with newdata
for data in info:
valueBoundry = data.find(":")
if seekValue == data[0:(valueBoundry)]:
print "writing new value"
newValue = data[0:(valueBoundry+1)] + str(newData)
#write to our temp file
newpps.write(newValue)
else: newpps.write(data)
pps.close()
close(holder)
newpps.close()
#remove original file
remove(file)
#move temp file to pps
copy(temp,"/pps/ohm.pps")