Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
opening a file
#1
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.
Reply
#2
with open('C:/Users/j_pra/Desktop/98-0.txt','r', encoding='utf8') as myfile:
Reply
#3
Yeah sorry i realized that thank you so much
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Facing Problem while opening a file through command prompt vlearner 4 1,940 Jan-30-2022, 08:10 AM
Last Post: snippsat
  Subprocesses not opening File Select Dialog teut 2 2,428 Feb-22-2021, 08:07 PM
Last Post: teut
  Opening file and outputting its text content example leodavinci1990 1 1,898 Oct-12-2020, 05:33 AM
Last Post: buran
  File Opening Hitso 10 5,305 Jun-05-2020, 10:35 AM
Last Post: DeaD_EyE
  Test a file for a string without opening it? tester_V 2 2,162 Jun-03-2020, 06:40 PM
Last Post: tester_V
  How to assess elapsed time to execute a .exe file or opening a desktop application? Sudershan 2 2,150 Apr-18-2020, 01:40 PM
Last Post: buran
  Opening a file amitsinbox 6 3,201 Apr-13-2020, 11:54 AM
Last Post: amitsinbox
  Opening CSV file from SFTP server not working cluelessintern 0 2,789 Apr-08-2020, 08:10 PM
Last Post: cluelessintern
  How To Find an Opening and Closing String, Copying Open/Close/Contents to New File davidshq 1 2,052 Mar-03-2020, 04:47 AM
Last Post: davidshq
  Error -3 when opening matlab file in python python_newbie09 0 2,311 Aug-02-2019, 11:51 AM
Last Post: python_newbie09

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020