python读写文件

f = open("./data/test.txt","r")
lines = f.readlines()
for line in lines:
    print(line)

 

UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 2729: illegal multibyte sequence 解决方案:

f = open("./data/happy.txt", "r", encoding='utf-8')

 

 python写文件

f = open('test.txt', 'w')
f.write('Hello, world!')
f.close()

 

posted on 2020-01-22 21:37  穷酸秀才大草包  阅读(165)  评论(0编辑  收藏  举报

导航