| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
代码如下: 
import time 
import datetime 
 
filePath = r'C:\Users\Administrator\Desktop{}'.format('\\') 
file = r'{}.txt'.format(datetime.datetime.today()) 
 
with open(filePath+file, 'w') as f: 
    f.write('asdfg') 
 
错误提示如下: 
with open(self.filePath + self.file, 'w') as f: 
OSError: [Errno 22] Invalid argument: 'C:\\Users\\Administrator\\Desktop\\2022-05-22 09:59:44.001414.txt' 
 
各位大神,请问一下这是什么问题。我直接在windows下新建2022-05-22 09:59:44.001414.txt是没问题的。
windows下面文件名称不能包括以下字符: 
你说的直接新建没问题看一下名字还是你输入的名字吗, windows会直接将违法的字符串改掉好像 
建议使用下划线  
 
 
 |   
 
 
 
 |