ConfigParser and unicode: a simple solution?

F

Frank Niessink

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 = SafeConfigParser(...)
encoded_filename = filename.encode('unicode_escape')
settings.set('file', 'currentfilename', encoded_filename)

And of course doing the reverse when getting the filename:

settings = SafeConfigParser(...)
encoded_filename = settings.get('file', 'currentfilename')
filename = filename.decode('unicode_escape')

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top