今天打卡,出了个bug:
Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/python.py", line 18, in <module>
dt = time.strftime("%Y{y}%M{m}%D{d} %H{h}:%MI{mi}:%S{s}".format(y="年",m="月",d="天",h="小时",mi="分钟",s="秒"))
UnicodeEncodeError: 'locale' codec can't encode character '\u5e74' in position 2: encoding error
源代码:
import os
from shutil import copy
from shutil import move
import time
path="文件夹"
for filepath,folders,files in os.walk(path):
# print(files,filepath,)
for file in files:
create_time = os.path.getmtime(os.path.join(filepath, file))
print(create_time)
# 时间戳 2018 1 2 3 4 5 6...
# print(create_time)
# 格式化 显示2018-03-21 22:00
realtime = time.localtime(create_time)
dt = time.strftime("%Y{y}%M{m}%D{d} %H{h}:%MI{mi}:%S{s}".format(y="年",m="月",d="天",h="小时",mi="分钟",s="秒"))
print(dt)