执行以下python代码时出错:
#!/comm/python/stable/bin/python
import re
import os
import shutil
DestDir="/home/SVModels/"
vamsList="/home/vamsList.txt"
with open(vamsList) as f:
for line in f:
fileObj= re.split (r'(/)', line)
OldfileName=fileObj[-1]
NewfileName=".".join([fileObj[14], "sv"])
shutil.copy(line.rstrip(), DestDir)
print("OldfileName= {}NewfileName= {}".format(OldfileName, NewfileName))
os.chdir(DestDir)
print "Current working dir : %s" % os.getcwd()
os.rename(OldfileName,NewfileName)
错误如下:
^{pr2}$看起来是假的操作系统重命名无法用字符串替换“OldfileName”。当我真的改变操作系统重命名命令硬引用“OldfileName”,然后它就可以工作了。 例如。操作系统重命名("我的文件.vams“,新文件名)
你知道为什么原来的代码不起作用吗?在
目前没有回答
相关问题 更多 >
编程相关推荐