ConfigParser and unicode: a simple solution?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Niessink

    #1

    ConfigParser and unicode: a simple solution?

    Dear list members,

    I'm using ConfigParser to read and write simple configuration files. One
    of the items written is the file the user is currently working on, so
    that the application can load that same file when the user starts the
    application for a new session.

    However, filenames may not be simple ascii strings, but can very well be
    unicode strings. Would a simple solution to store the filename in the
    ..ini file be to encode it with 'unicode_escape ' before calling
    configparse.set (section, setting, filename)? For example:

    settings = SafeConfigParse r(...)
    encoded_filenam e = filename.encode ('unicode_escap e')
    settings.set('f ile', 'currentfilenam e', encoded_filenam e)

    And of course doing the reverse when getting the filename:

    settings = SafeConfigParse r(...)
    encoded_filenam e = settings.get('f ile', 'currentfilenam e')
    filename = filename.decode ('unicode_escap e')

    Would this work? Any caveats?

    Thanks, Frank

    PS: I'm aware of a bunch of alternatives to ConfigParsers, so if the
    above solution is not feasible, I'll probably have to incorporate one of
    these alternatives in my app.
Working...