while True:
txt = ''
while len(txt)<3:
txt += input("请输入文字:") + '\n'
with open('/storage/emulated/0/1/3.txt', 'a+') as f:
f.write(txt)
from datetime import datetime
import time
print(datetime.now())
print(datetime.today())
用str()把日期时间类转成字符串型数据就能写入了:
import os
path = 'd:\\mydir'
if not os.path.exists(path):
os.mkdir(path)
from datetime import datetime
Time = str(datetime.today())
with open(path+'\\test.txt', 'w') as f:
f.write( Time )