[Python-bugs-list] [ python-Bugs-810843 ] Support for non-string
data in ConfigParser unclear/buggy
SourceForge.net
noreply at sourceforge.net
Mon Sep 22 17:58:21 EDT 2003
Bugs item #810843, was opened at 2003-09-22 21:58
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=810843&group_id=5470
Category: None
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: curby (kirbysdl)
Assigned to: Nobody/Anonymous (nobody)
Summary: Support for non-string data in ConfigParser unclear/buggy
Initial Comment:
In my current project, I'm using ConfigParser to read
configuration files as well as manage internal
configuration. The following test script generates an
error because values of options must be strings in
order for ConfigParser to run smoothly. (It's short
enough that I'm including it here for reference; I'm
also attaching it).
#----- BEGIN TEST -----
#!/usr/bin/env python
import ConfigParser
import sys
conf = ConfigParser.ConfigParser()
conf.add_section("sect")
conf.set("sect","option",2)
conf.write(sys.stderr)
conf.get("sect","option")
#----- END TEST -----
>From the ConfigParser code, I see that the value isn't
checked to make sure it is a string before string
methods are applied to it.
I'm currently using the raw parameter to get() (see
http://www.python.org/doc/lib/ConfigParser-objects.html#l2h-1261)
in order to circumvent the problem.
I'd suggest one or more of the following:
(1) Casting the option to a string explicitly instead
of assuming it is a string (this could also be done in
the set() method).
(2) Checking that the option is a string instead of
assuming it is a string.
(3) Stating in the documentation that the set() method
should only take values of type string.
(4) Stating in the documentation that the raw parameter
should be used when an option's value might not be of
type string (this might be the intended usage, but it
isn't made clear).
I hope none of these are too difficult to implement,
but I understand that this is a noncritical problem.
Nonetheless, I was shocked to see what I thought was a
straightforward use of ConfigParser throw off errors.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=810843&group_id=5470
More information about the Python-bugs-list
mailing list