怎么使用Python创建文件并编辑?

'''
https://www.cnblogs.com/xiazhenyu/
*** 学而思之、思而记之、记而习之 ***
'''
f="dict_file.txt" #定义文件名
def writefile(key,value):
with open(f, "w") as file: # 只需要将之前的”w"改为“a"即可,代表追加内容,“w”是覆盖
file.write(str(key) + "=" + str(value) +"\n")
return f
writefile("user","lalala")
#写入结果 user=lalala
posted @ 2020-09-24 23:40  sunny.boy  阅读(2047)  评论(0编辑  收藏  举报