UnicodeError for join()

tmallen thomasmallen at gmail.com
Thu Jan 15 22:34:19 CET 2009

On Jan 15, 4:09 pm, "Martin v. Löwis" <mar... at v.loewis.de> wrote:
> >> 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

Thanks, it was the title that was causing problems. I just added the
encode() part to the self.title assignment.


More information about the Python-list mailing list