Python OSError: [Errno 22] Invalid argument:的出现和解决

 
复制代码
【转自https://www.cnblogs.com/Owen-ET/】
1 if __name__ == '__main__':
2 startime = time.strftime('%H:%M:%S') 3 print("开始时间为:%s" % startime) 4 #测试路径 5 test_dir = './t/test_case' 6 #报告路径 7 report_dir = './t/report/' 8 9 now = time.strftime('%Y-%m-%d_%H:%M:%S') 10 # 创建完整报告文件 11 filename = report_dir + now + '_report.html' 12 fp = open(filename,'wb')
复制代码

 看到没有!!看第九行,now的获取时间有问题!!!时分秒之间不能用冒号:,不能用冒号:,不能用冒号:,重要的事情说三遍!!!

修改如下:

复制代码
 1 if __name__ == '__main__':
 2     startime = time.strftime('%H:%M:%S')
 3     print("开始时间为:%s" % startime)
 4     #测试路径
 5     test_dir = './t/test_case'
 6     #报告路径
 7     report_dir = './t/report/'
 8 
 9     now = time.strftime('%Y-%m-%d_%H_%M_%S')
10     # 创建完整报告文件
11     filename = report_dir + now + '_report.html'
12     fp = open(filename,'wb')
复制代码
原文地址:https://www.cnblogs.com/yanhuidj/p/11351561.html