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.

0

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.