473,395 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 = 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.
Feb 22 '06 #1
0 1201

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: thehaas | last post by:
I'm trying to read a config file with Unicode characters via ConfigParser with Python 2.3 and am having some problems. The file looks like: goodProcRef=PYTHON,RSS,Grüß,LDAP This is how...
3
by: Stephen Boulet | last post by:
I'm having a bit of trouble getting my head around the ConfigParser module. I have a very simple configuration file; maybe the easiest thing to do would be to show that: ============ # Add a...
14
by: Michael Chermside | last post by:
A few weeks ago, the suggestion was made on Python-Dev that it might be time to consider replacing the ConfigParser module and that we should hold a "shootout" (ie ask for implementations and see...
2
by: rzed | last post by:
I am working with PythonCard in one of my apps. For its purposes, it uses an .ini file that is passed to ConfigParser. For my app, I also need configuration information, but for various reasons,...
3
by: Sergey | last post by:
Is there an alternative to standard module ConfigParser, which can use delimitier symbol other than ":" and "=", preferaby just space? I need to parse such configs: 2:5020/758 xxxx 2:5020/794...
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
1
by: pipehappy | last post by:
Hello everyone: I came across the module ConfigParser and can use it correctly. import ConfigParser fp = open('test.cfg','w+') config = ConfigParser.ConfigParser() config.readfp(fp)...
7
by: stef | last post by:
hello, I just used configparser for the first time and discovered that it shuffled all my sections, and the contents of the sections too. This makes human manipulation of the file impossible....
2
by: stef mientki | last post by:
hello, Why does Configparser change names to lowercase ? As Python is case sensitive (which btw I don't like at all ;-) but now when really need the casesensitivity, because it handles about...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.