[Tutor] Encode problem

Kent Johnson kent37 at tds.net
Tue May 5 12:37:53 CEST 2009


On Tue, May 5, 2009 at 1:14 AM, Mark Tolonen <metolone+gmane at gmail.com> wrote:

> The below works.  ConfigParser isn't written to support Unicode correctly. I
> was able to get Unicode sections to write out, but it was just luck. Unicode
> keys and values break as the OP discovered.  So treat everything as byte
> strings:

Thanks for the complete example.

> files = glob.glob('*.txt')
> c.add_section('files')
>
> for i,fn in enumerate(files):
>   fn = fn.decode(sys.getfilesystemencoding())

I think if you give a Unicode string to glob.glob(), e.g.
glob.glob(u'*.txt'), then the strings returned will also be unicode
and this decode step will not be needed.

Kent


More information about the Tutor mailing list