Generating a unique filename in the face of unicode filename

"Martin v. Löwis" martin at v.loewis.de
Sun Jun 14 11:52:32 EDT 2009


> where line 175 is the assignment to self.unique_name.  After a little
> back-and-forth with his user it turns out that her computer's hostname
> contains non-ASCII data, so presumably self.hostname is a unicode object.

Most likely, it is not. It's rather the hostname encoded in the ANSI
code page.

> It works for Frank on his Windows box as well.  Any ideas how to properly
> Unicode-proof this code?

You should first decode the gethostname result, using the locale's
encoding; expect this decoding to fail possibly, so the "ignore" error
handler might be your best choice.

Regards,
Martin



More information about the Python-list mailing list