Python Forum
opening a file - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: opening a file (/thread-6754.html)



opening a file - baronmontesqieu - Dec-06-2017

i am trying to open a file.
it is not letting me read the file.

WHY?
this is my code
with open('C:/Users/j_pra/Desktop/98-0.txt','r') as myfile:
    print (myfile.read())
and this is the error i am getting
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-3-24de5ab647f0> in <module>()
      1 with open('C:/Users/j_pra/Desktop/98-0.txt','r') as myfile:
----> 2     print (myfile.read())

~\Anaconda3\lib\encodings\cp1252.py in decode(self, input, final)
     21 class IncrementalDecoder(codecs.IncrementalDecoder):
     22     def decode(self, input, final=False):
---> 23         return codecs.charmap_decode(input,self.errors,decoding_table)[0]
     24 
     25 class StreamWriter(Codec,codecs.StreamWriter):

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 6552: character maps to <undefined>
please help soon.
Thank you.


RE: opening a file - Larz60+ - Dec-06-2017

with open('C:/Users/j_pra/Desktop/98-0.txt','r', encoding='utf8') as myfile:



RE: opening a file - baronmontesqieu - Dec-06-2017

Yeah sorry i realized that thank you so much