Python Forum

Full Version: opening a file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
with open('C:/Users/j_pra/Desktop/98-0.txt','r', encoding='utf8') as myfile:
Yeah sorry i realized that thank you so much