Gordon Williams
2003-10-06 20:04:25 UTC
Hi All,
There is a consistency problem between the RawConfigParser and the
ConfigParser and SafeConfigParser with the items method. In the first case
a list of tuples is returned and in the second two a generator is returned.
This is quite confusing and I thought that this was a bug, but the docs
indicate that this is what is supposed to happen.
An items method that returned a list of tuples as it does in the
RawconfigParser would be a useful method to have for both ConfigParser and
SafeConfigParser.
The RawConfigParser docs say that items should return a list:
items( section)
Return a list of (name, value) pairs for each option in the given section.
The ConfigParser docs say that items should return a generator:
items( section[, raw[, vars]])
Create a generator which will return a tuple (name, value) for each option
in the given section. Optional arguments have the same meaning as for the
get() method. New in version 2.3.
... print item
...
('age', '21')
('company', 'Aztec')
('name', 'karthik')
... print item
...
('age', '21')
('company', 'Aztec')
('name', 'karthik')
It doesn't make sense to me that the same method should return different
objects. Maybe another name for ConfigParser and SafeConfigParser would be
appropriate to indicate that a generator was being returned.
Regards,
Gordon Williams
There is a consistency problem between the RawConfigParser and the
ConfigParser and SafeConfigParser with the items method. In the first case
a list of tuples is returned and in the second two a generator is returned.
This is quite confusing and I thought that this was a bug, but the docs
indicate that this is what is supposed to happen.
An items method that returned a list of tuples as it does in the
RawconfigParser would be a useful method to have for both ConfigParser and
SafeConfigParser.
The RawConfigParser docs say that items should return a list:
items( section)
Return a list of (name, value) pairs for each option in the given section.
The ConfigParser docs say that items should return a generator:
items( section[, raw[, vars]])
Create a generator which will return a tuple (name, value) for each option
in the given section. Optional arguments have the same meaning as for the
get() method. New in version 2.3.
Config.config
<ConfigParser.RawConfigParser instance at 0x00E0DAD0>Config.config.items("personal")
[('age', '21'), ('company', 'Aztec'), ('name', 'karthik')]Config.config
<ConfigParser.SafeConfigParser instance at 0x00DB1738>Config.config.items("personal")
<generator object at 0x00DC3350>... print item
...
('age', '21')
('company', 'Aztec')
('name', 'karthik')
Config.config
<ConfigParser.ConfigParser instance at 0x00E0D378>Config.config.items("personal")
<generator object at 0x00DB1738>... print item
...
('age', '21')
('company', 'Aztec')
('name', 'karthik')
It doesn't make sense to me that the same method should return different
objects. Maybe another name for ConfigParser and SafeConfigParser would be
appropriate to indicate that a generator was being returned.
Regards,
Gordon Williams