This commit is contained in:
2024-08-19 01:59:23 +08:00
parent b06c392e7c
commit 741f8ae5c1
3 changed files with 10 additions and 5 deletions

View File

@@ -56,10 +56,15 @@ def open_file(filename='a', file_format='.txt', mode='add'):
f = open(filename+file_format, 'w', encoding='UTF-8')
return f
# 打印到TXT文件
def print_to_file(content, filename='print_result', file_format='.txt'):
def print_to_file(*args, filename='print_result', file_format='.txt', print_on=True):
if print_on==True:
for arg in args:
print(arg, end=' ')
print()
f = open(filename+file_format, 'a', encoding='UTF-8')
f.write(content+'\n')
for arg in args:
f.write(str(arg)+' ')
f.write('\n')
f.close()
# 读取文本文件内容。如果文件不存在,返回空字符串