1

I am trying to write into a file (in Python), but it says:

'ManyRelatedManager' object has no attribute 'encode'

Here is the code:

self.writer.writerow([s.encode('utf-8') for s in row])

Is there a way to avoid/fix this ?

JJJ
  • 32,902
  • 20
  • 89
  • 102
doniyor
  • 36,596
  • 57
  • 175
  • 260
  • Just do this: http://stackoverflow.com/questions/934160/write-to-utf-8-file-in-python – Chris Laplante Aug 20 '11 at 14:19
  • @SimpleCoder: The csv module doesn't support unicode -> http://docs.python.org/library/csv.html – Rosh Oxymoron Aug 20 '11 at 14:32
  • yeah, but it says: "Accordingly, all input should be UTF-8 or printable ASCII to be safe;..." which is my case. the thing is that my 's' object is not a unicode object, i should change it to unicode object. – doniyor Aug 20 '11 at 14:54
  • the thing is: it is working fine with thise code: w.writerow([u"%d"%s.id,s.name,u"%d"%s.clicks,s.status,s.stand.nick]) but not with this one: w.writerow([u"%d"%s.id,s.name,u"%d"%s.clicks,s.status,s.stand.nick,s.studiengaenge]) because 'studiengaenge' purportedly isnot a unicode object. can that be a reason for my problem.. ? – doniyor Aug 20 '11 at 14:56

1 Answers1

2

in your code

self.writer.writerow([s.encode('utf-8') for s in row])

the "s" object may not a unicode object you should try change your "s" object to unicode first

timger
  • 944
  • 2
  • 13
  • 31