文件操作
# 往一个文件里写内容
# mode='a': 追加
def wFileContent(path='', content='', mode='a'):
if len(path) == 0:
print("path不存在", "\n")
return
fx = None
try:
fx = open(file=path, mode=mode, encoding='utf-8') # 打开文件
if isinstance(content, list):
content = "".join('%s' % strItem for strItem in content)
elif isinstance(content, tuple):
content = "".join('%s' % strItem for strItem in content)
elif isinstance(content, str):
content = content
content += "\n"
fx.write(content)
fx.close()
except Exception as e:
print("文件操作失败", "\n")
exit()
上次更新: 2022/08/23, 18:58:25