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 ?

4
  • Just do this: stackoverflow.com/questions/934160/… Commented Aug 20, 2011 at 14:19
  • @SimpleCoder: The csv module doesn't support unicode -> docs.python.org/library/csv.html Commented Aug 20, 2011 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. Commented Aug 20, 2011 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.. ? Commented Aug 20, 2011 at 14:56

1 Answer 1

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

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.