用with……as写文件想跳出?
def my_log(i): date = os.popen('@date /t').readlines()[0].replace('/','-')[0:10] with open(f'{date}.txt','a+') as f: f.write(i) f.close() my_log('写入的字符')
如果指定文件名在加个参数就行