我试图重新命名一个名为output.txt
与蟒蛇时间戳的文件,但我得到错误文件:重命名在python
Traceback (most recent call last):
File "D:/Python27/rename.py", line 10, in <module>
os.rename('output.txt', newfile)
WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect
我的代码如下:
import datetime
import os
dt = str(datetime.datetime.now())
newtime = ".".join(dt[0:19].split())
newfile = 'output'+newtime+'.txt'
os.rename('output.txt', newfile)
冒号(:)不允许在Windows中的文件名。 –