import os
import time
basedir = os.path.abspath(os.path.dirname(__file__))
print(basedir)
t1 = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
print(t1)
with open(basedir+"/"+"1.txt","a",encoding = "utf-8") as f:
f.write(t1+":"+"hello")
f.write("\r\n")
f.close()

本文介绍了使用Python进行文件操作和获取当前时间戳的方法。通过os模块获取当前文件的绝对路径,并利用time模块获取并格式化当前时间。然后将时间戳和字符串写入指定目录下的文本文件中。
327

被折叠的 条评论
为什么被折叠?



