0

im trying to extract the flight details for a project. i was able to extract the information but when im writing the extracted list, into the csv, im facing issue with rupee symbol represented as a garbage value . image attached below and code used below

below is the code ,

with open(output_file, 'w') as f:
    writer = csv.writer(f)
    for row in flights_data:
        row = [s.encode('utf-8') for s in row]
        writer.writerows([row])
f.close()

output file looked like this

output file

deceze
  • 510,633
  • 85
  • 743
  • 889
AMR
  • 1
  • 2
  • Which program do you use to view the CSV file you have created? – mkrieger1 Jul 08 '20 at 10:44
  • Please post a relevant of the input data here. – Ronald Jul 08 '20 at 10:44
  • Microsoft excel – AMR Jul 08 '20 at 10:45
  • Don't `.encode('utf-8')`, just pass `encoding='utf-8'` to `open()`. Further, look at the resulting file in a hex editor to see how the bytes are actually encoded and whether they correspond to the expected UTF-8 encoding of the character. If that's all working, then it's probably Excel notoriously failing at reading UTF-8 CSVs again. – deceze Jul 08 '20 at 10:46
  • The trailing `f.close()` is superfluous BTW, that's already handled by the `with` block. – deceze Jul 08 '20 at 10:46
  • I tried adding encoding=utf-8 to open, but that simply gave me a error asking me to remove that argument – AMR Jul 08 '20 at 10:55
  • Wat? What's the exact error message? Have you tried any of the other things I recommended? – deceze Jul 08 '20 at 10:58
  • it worked with encoding , thanks all – AMR Jul 10 '20 at 06:43
  • i used python 2.7 venv, when i changed to 3.7 it worked with adding utf-8 – AMR Jul 10 '20 at 06:43

0 Answers0