0

I have a python code in that writing csv file.when i run the code in Ubuntu it is running when i run code in windows its creating error.

fp = open('result2.csv', 'a')
fp.write(post+'\t'+str(post_issue_list)+'\n')
fp.close()

UnicodeEncodeError:

'charmap' codec can't encode character '\u2764' is position 26: character maps to undefined>

fp.write(post+'\t'+str(post_issue_list)+'\n')

in this line error coming only when i run in windows,its fine in ubuntu

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Abdul Raoof
  • 133
  • 7
  • 1
    Why are you not using the [`csv`](https://docs.python.org/3/library/csv.html) module? – roganjosh Aug 11 '18 at 13:26
  • 1
    The error you are facing is due to encoding of the file. Try changing the encoding of the file to 'utf-8' or others. – Abhi Aug 11 '18 at 13:36

1 Answers1

0

Add encoding parameter in open() and then write the file:

fp = open('result2.csv', 'a', encoding='utf-8')
georgeawg
  • 48,608
  • 13
  • 72
  • 95