UnicodeError for join()

"Martin v. Löwis" martin at v.loewis.de
Thu Jan 15 16:09:07 EST 2009


>> One of self.title and self.content is a Unicode string, the other is
>> a byte string. You need to change them to have the same type (depending
>> on whether you want to process them as Unicode or byte strings).
>>
> 
> How can I do that?

First, you need to find out what the respective types are:

print type(self.title), type(self.content), repr(self.title),
repr(self.content)

With that information, as a very important next step, you need to
understand why the error occurs.

Then, you need to fix it, e.g. by converting all strings to byte
strings.
Suppose title is a unicode string, and further suppose the output
is to be encoded in cp1252, then you change the line to

rc_file.write(u"\n\n".join([self.title.encode("cp1252"),
                            "### BEGIN CONTENT ###",
                            self.content]))

Regards,
Martin



More information about the Python-list mailing list