How do I remove the u letter in the python script? when I run the following script, it exports data to CSV from Mongodb, but it brings u letters in CSV fiel. I tried to use many solution that did not work. please someone can help me.
the sample of python script :
import codecs
import csv
cursor = db.workflows.find( {}, {'_id': 1, 'stages.interview': 1, 'stages.hmNotification': 1, 'stages.hmStage': 1, 'stages.type':1, 'stages.isEditable':1, 'stages.order':1, 'stages.name.en':1, 'stages.stageId':1 })
with codecs.open('stages2.csv', 'w', encoding='utf-8') as outfile:
fields = ['_id', 'stages.interview', 'stages.hmNotification', 'stages.hmStage', 'stages.type', 'stages.isEditable','stages.order', 'stages.name', 'stages.stageId']
write = csv.DictWriter(outfile, fieldnames=fields)
write.writeheader()
for stages_record in cursor:
stages_record_id = stages_record['_id']
for stage_record in stages_record['stages']:
x = {
'_id': stages_record_id,
'stages.interview': stage_record['interview'],
'stages.hmNotification': stage_record['hmNotification'],
'stages.hmStage': stage_record['hmStage'],
'stages.type': stage_record.get('type'),
'stages.isEditable': stage_record['isEditable'],
'stages.order': stage_record['order'],
'stages.name': stage_record['name'],
'stages.stageId': stage_record['stageId']}
write.writerow(x)
The output of csv should not have '{u'en':u'", brackets'. how do I fix the python script? please help me.
the sample of CSV :
id,stages.interview,stages.hmNotification,stages.hmStage,stages.type,stages.isEditable,stages.order,stages.name,stages.stageId 5318cbd9a377f52a6a0f671f,False,False,False,new,False,0,{u'en': u'New'},51d1a2f4c0d9887b214f3694