0

I have opened and read csv files in python many times before, but for some reason I keep getting this error this time.

Error:

File "C:\Program Files\Python37\lib\encodings\cp1250.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 22: character maps to <undefined>

My code:

with open("databa.csv", 'r') as fp:
    for line in fp:
        print(line)

I have already tried renaming the file, setting the format as 'UTF8' or ignoring the errors ("databa.csv", 'r', errors='ignore') but none of it worked

with open(r"databa.csv", 'rb') as fp: 
with open("databa.csv", 'r', buffering=0) as fp: 
with open("databa.csv", errors="ignore") as fp: 
with open("databa.csv",encoding='utf8', errors="ignore") as fp: 
with open("databa.csv",encoding='utf8', "r") as fp: 
with open("databa.csv", encoding='utf8', "r") as fp
9
  • I have already tried...setting the format as 'UTF-8' can you show what you tried? Commented Sep 24, 2019 at 19:45
  • I have tried this: with open(r"databa.csv", 'rb') as fp: with open("databa.csv", 'r', buffering=0) as fp: with open("databa.csv", errors="ignore") as fp: with open("databa.csv",encoding='utf8', errors="ignore") as fp: with open("databa.csv",encoding='utf8', "r") as fp: with open("databa.csv", encoding='utf8', "r") as fp: Commented Sep 24, 2019 at 19:50
  • Can you paste some contents of the csv file? Commented Sep 24, 2019 at 19:51
  • 2
    edit question and put code from comment. It will be more readable in question. Commented Sep 24, 2019 at 19:52
  • 1
    always put code, data and error messages in question. it will be more readable. You can't format it in comment. Commented Sep 24, 2019 at 19:53

1 Answer 1

1

I ran the example you provided and it works perfectly fine without any issues:

enter image description here

Sample data provided:

enter image description here

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.