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()