ConfigParser and Unicode

thehaas at binary.net thehaas at binary.net
Thu Mar 18 12:41:36 EST 2004


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:

   [DEFAULT]
   goodProcRef=PYTHON,RSS,Grüß,LDAP

This is how I'm trying to read it:
  config = ConfigParser()
  config.read("work.cfg")
  goodProcRef = config.get(section,"goodprocref").split(",")

goodProcRef now looks like this:
   >>> goodProcRef
   ['PYTHON', 'RSS', 'Gr\xfc\xdf', 'LDAP'] 

Obviously, 'Grüß'!='Gr\xfc\xdf' .  If I change the split to use u","
instead, I get the following:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "work.py", line 165, in parseConfig
    goodProcRef = config.get(section,"goodprocref").split(u",")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 13: ordinal not in range(128)

Any ideas on how I can get the correct value?


-- 
Mike Hostetler          
thehaas at binary.net 
http://www.binary.net/thehaas 



More information about the Python-list mailing list