0

I am trying to read .res files and this is the error I get :

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xda in position 27: invalid continuation byte.

I tried studying similar problem solutions but nothing is working out. Please find below my piece of code:

   df = pd.DataFrame()

    for filename in os.listdir():

        #with open(filename, encoding='utf-8') as f:
        #F=filename.read().split()

        if filename.endswith(".res"):

            Data=open(filename)
            F=Data.read()
PApostol
  • 2,152
  • 2
  • 11
  • 21
  • 1
    Is the format of your file UTF-8? If it isn't then that's your problem. Python is trying to read that file as UTF-8 and is failing because it's some other format. I'd suggest that you try changing your open line to `Data=open(filename, 'rb')` – CryptoFool Sep 27 '20 at 22:28
  • I tried doing that but end up getting b written in front of data in dataframe – Shailee Yagnik Sep 29 '20 at 16:13

1 Answers1

0

A .res file is usually a resource file written in C++ that contains compiled code which is used on Windows systems. It is not a text file, which is what your code assumes with Data=open(filename) and F=Data.read(). Please see this answer on how to access resource files in Python.

PApostol
  • 2,152
  • 2
  • 11
  • 21