I have obtained a data.txt file from an online source. When I open the file with Notepad, I see the random characters as shown in the figure.
I attempted to open the file using the following python code snippet:
my_file = 'data.txt'
f = open(my_file, 'rb')
print(f)
ff = pickle.load(f)
print(ff)
f.close()
The first print operation gives <_io.BufferedReader name='data.txt'>
in the console. And the second print operation displays all the data of data.txt
file in a readable form.
I want to edit the data in the data.txt
file with my own data sets. I googled for possible solutions. Most of the available solutions (for example this) suggest changing the Encoding scheme of the data.txt
file to UTF-8
. At present, the data.txt
Encoding is ANSI. I changed the Encoding to UTF-8 as suggested. However, the problem still persists (file still contains gibberish). Moreover, I tried to see the contents of the file (now UTF-8 encoding) using the above python code snippet. This time, I get the following error.
_pickle.UnpicklingError: invalid load key, '\xef'.
The python code shows that the file has valid data. However, I'm unable to edit the data with my own data sets. Any help, please!