0
How can I open the file for working with it? Python3
Hi, I want to open the file on my laptop rich.txt and “import” the words from this file to my word list , but first to remove the spaces with split(), but I receive the message „utf-8 codec can’t decode byte 0x84 in position 10: invalid start byte.“ Can Someone explain what it means ? The link for my code: https://code.sololearn.com/cfDVeQVZMqO7/?ref=app
3 Respuestas
+ 4
in contrast to the comment from Mirielle, it is possible to open *.txt files. Here a very short an basic demonstration of reading and writing files.
with open('Tex.txt', 'w+') as f:
f.write('line1\n' 'line2\n' 'this is the end my friend\n')
f.seek(0)
print(f.read())
Resding from the file itself and importing the content of the file can differ a bit, because it depends how the file was created, e.g. on windows, linux or macOs. But this is only about the way how newline characters are used during file creation.
+ 4
Katja, are you sure that your file is a txt file or is it a rich-text file? Rich-text files contain formatted text, which is not suitable for you. If your input file is Rich-text, you should save the file in a simple text file, that can be used for importing.