0

I write some files as .txt with python3.6 in mac. And then, when I try to read them using:

f = open(...,'r')
lines = f.readlines()

I got this error:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 10: invalid continuation byte

Can anyone help? Thank you.

user3483203
  • 50,081
  • 9
  • 65
  • 94
Yanpei
  • 31
  • 1
  • 4

1 Answers1

0

How do you create file in python? Can you please show full example of your code? I am also working on Mac, but no issues. Please see one of simple examples below on how it works:

create file:

file = open('test9.txt', 'w')
file.write('first \n second line \n aaa')
file.close()

read file:

with open('test9.txt') as f:
    lines = f.readlines()
    print(lines)

created file is a plain text document with .txt

Blacho
  • 87
  • 1
  • 1
  • 8
  • Thank you for help. My writing code is: f = open(moving_train+file_name,'w',encoding = 'utf-8') for i in range(len(data)): f.write(data[i]) f.close() where moving_train and filename is string, and data is a list of strings and for reading these files, the code is f = open(train_y+name,'r') lines = f.readlines() f.close() – Yanpei Jun 02 '18 at 22:22