473,573 Members | 2,835 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ConfigParser: what read('non-existent-filename') returns in 2.3.x?

Wrote a little "user-friedly" wrapper for ConfigParser for a KDE's
SuperKaramba widget.
(http://www.kde-look.org/content/show.php?content=32185)

I was using 2.4.x python docs as reference and
ConfigParser.re ad('non-existent-filename') returns [] in 2.4.x

One user with 2.3.x reported an error stemming from my use of
len(cfgObject.r ead('potentiall y-non-existent-filename'))

File "/home/web/Downloads/afoto-1.5b6.skz/localConf.py", line 53, in load
TypeError: len() of unsized object

Can anyone tell me what cfgObject.read( 'potentially-non-existent-filename')
returns in 2.3.x?

My output:
>>import ConfigParser
cfg = ConfigParser.Co nfigParser()
a = cfg.read('adsfa sfdasfd')
a, len(a), type(a)
([], 0, <type 'list'>)

Thx in advance.

Daniel.
Jul 20 '06 #1
4 1857
On Thu, Jul 20, 2006 at 10:50:40AM -0700, Danil Dotsenko wrote:
Wrote a little "user-friedly" wrapper for ConfigParser for a KDE's
SuperKaramba widget.
(http://www.kde-look.org/content/show.php?content=32185)

I was using 2.4.x python docs as reference and
ConfigParser.re ad('non-existent-filename') returns [] in 2.4.x
http://docs.python.org/lib/RawConfigParser-objects.html
That agrees with the docs since read returns a list of successfully parsed
filenames. Note the docs also say this was added in 2.4.
>
One user with 2.3.x reported an error stemming from my use of
len(cfgObject.r ead('potentiall y-non-existent-filename'))

File "/home/web/Downloads/afoto-1.5b6.skz/localConf.py", line 53, in load
TypeError: len() of unsized object

Can anyone tell me what cfgObject.read( 'potentially-non-existent-filename')
returns in 2.3.x?
I suspect it never returns anything which means you are getting None instead
of a list, which would give you the exception above.
>
My output:
>import ConfigParser
cfg = ConfigParser.Co nfigParser()
a = cfg.read('adsfa sfdasfd')
a, len(a), type(a)
([], 0, <type 'list'>)

Thx in advance.

Daniel.
--
http://mail.python.org/mailman/listinfo/python-list
Jul 20 '06 #2
Danil Dotsenko wrote:
Chris Lambacher wrote:
>On Thu, Jul 20, 2006 at 10:50:40AM -0700, Danil Dotsenko wrote:
>>Wrote a little "user-friedly" wrapper for ConfigParser for a KDE's
SuperKaramb a widget.
(http://www.kde-look.org/content/show.php?content=32185)

I was using 2.4.x python docs as reference and
ConfigParser. read('non-existent-filename') returns [] in 2.4.x
http://docs.python.org/lib/RawConfigParser-objects.html
That agrees with the docs since read returns a list of successfully
parsed
filenames. Note the docs also say this was added in 2.4.

I just looked at the
http://www.python.org/doc/2.3.5/lib/...r-objects.html
(note the version number) and see the following:
"If none of the named files exist, the ConfigParser instance will contain
an empty dataset." Which to me means []. To the least of it, the statement
should be clarified, but I would still kindly prefer to have someone
respond / confirm the procedure bellow gives different results in 2.3.x.
>>>import ConfigParser
cfg = ConfigParser.Co nfigParser()
a = cfg.read('adsfa sfdasfd')
a, len(a), type(a)
([], 0, <type 'list'>)

Thx in advance.
Python 2.3.5 (#2, Jun 13 2006, 23:12:55)
[GCC 4.1.2 20060613 (prerelease) (Debian 4.1.1-4)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
¬*>>import ConfigParser
¬*>>cfg = ConfigParser.Co nfigParser()
¬*>>a = cfg.read('adsfa sfdasfd')
¬*>>a
¬*>>type(a)
<type 'NoneType'>
¬*>>len(a)
Traceback (most recent call last):
¬* File "<stdin>", line 1, in ?
TypeError: len() of unsized object
¬*>>¬*
Jul 20 '06 #3
Chris Lambacher wrote:
On Thu, Jul 20, 2006 at 10:50:40AM -0700, Danil Dotsenko wrote:
>Wrote a little "user-friedly" wrapper for ConfigParser for a KDE's
SuperKaramba widget.
(http://www.kde-look.org/content/show.php?content=32185)

I was using 2.4.x python docs as reference and
ConfigParser.r ead('non-existent-filename') returns [] in 2.4.x
http://docs.python.org/lib/RawConfigParser-objects.html
That agrees with the docs since read returns a list of successfully parsed
filenames. Note the docs also say this was added in 2.4.
I just looked at the
http://www.python.org/doc/2.3.5/lib/...r-objects.html
(note the version number) and see the following:
"If none of the named files exist, the ConfigParser instance will contain an
empty dataset." Which to me means []. To the least of it, the statement
should be clarified, but I would still kindly prefer to have someone
respond / confirm the procedure bellow gives different results in 2.3.x.
>>import ConfigParser
cfg = ConfigParser.Co nfigParser()
a = cfg.read('adsfa sfdasfd')
a, len(a), type(a)
([], 0, <type 'list'>)
Thx in advance.

Jul 20 '06 #4
On Thu, Jul 20, 2006 at 02:01:08PM -0700, Danil Dotsenko wrote:
Chris Lambacher wrote:
On Thu, Jul 20, 2006 at 10:50:40AM -0700, Danil Dotsenko wrote:
Wrote a little "user-friedly" wrapper for ConfigParser for a KDE's
SuperKaramba widget.
(http://www.kde-look.org/content/show.php?content=32185)

I was using 2.4.x python docs as reference and
ConfigParser.re ad('non-existent-filename') returns [] in 2.4.x
http://docs.python.org/lib/RawConfigParser-objects.html
That agrees with the docs since read returns a list of successfully parsed
filenames. Note the docs also say this was added in 2.4.

I just looked at the
http://www.python.org/doc/2.3.5/lib/...r-objects.html
(note the version number) and see the following:
"If none of the named files exist, the ConfigParser instance will contain an
empty dataset." Which to me means []. To the least of it, the statement
should be clarified, but I would still kindly prefer to have someone
respond / confirm the procedure bellow gives different results in 2.3.x.
That says nothing about the return value. It says that the ConfigParser
object will contain an empty data set, ie:
config.sections () == []
NOT
config.read(['doesnotexist.c fg']) == []

since config.read does not explicitly return anything, and therefore you get
None.
>
>import ConfigParser
cfg = ConfigParser.Co nfigParser()
a = cfg.read('adsfa sfdasfd')
a, len(a), type(a)
([], 0, <type 'list'>)

Thx in advance.

--
http://mail.python.org/mailman/listinfo/python-list
Jul 21 '06 #5

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

Similar topics

3
2617
by: Greg Krohn | last post by:
I'm trying to subclass ConfigParser so I can use a custom __read method (the custom format doesn't conform to RFC 822) when needed. Needless to say, it's not working as expected. In the following code, I bind __read_ini to __read and override __read so it can choose between __read_ini and __read_custom. But it seems that __read_custom never...
1
1817
by: Martin Maney | last post by:
Summary: with batteries like these, get a longer extension cord? <transcript from interactive session> Python 2.2.1 (#1, Sep 7 2002, 14:34:30) on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from ConfigParser import ConfigParser >>> cp = ConfigParser()
2
4291
by: Roy H. Berger | last post by:
If I want to subclass ConfigParser and changed the optionxform method to not return things in lower case wouldn't I just need the following code in my subclasss module? from ConfigParser import * class MyConfigParser(ConfigParser): def __init__(self, defaults=None): ConfigParser.__init__(self, defaults)
11
4876
by: Manlio Perillo | last post by:
Regards. Since sections in CongiParser files are delimited by , why there is not an escape (and unescape) function for escaping &, characters to &amp;, &lbrack; and &rbrack; ? Thanks Manlio Perillo
2
1693
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, I'd rather use a syntax that ConfigParser can't handle. I know I can maintain two separate configuration files, and if I have to I will, but I'd...
10
11770
by: Terry Carroll | last post by:
It looks like ConfigParser will accept a list to be writing to the *.ini file; but when reading it back in, it treats it as a string. Example: ############################### import ConfigParser def whatzit(thingname, thing): print thingname, "value:", thing print thingname, "length:", len(thing)
1
2010
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) config.add_section('test') config.set('test', 'haha', 'hehe')
3
4336
by: tony.ha | last post by:
Hello I use ConfigParser as show below to read a config.txt file; from ConfigParser import ConfigParser config = ConfigParser() config.read('config.txt') items = config.items('FV') for item in items: module_name = item print module_name
3
1533
by: jamitwidme | last post by:
Hello. I am a novice programmer and have a question I have a configuration file(configuration.cfg) I read this from reading.py using ConfigParser When I use ConfigParser.get() function, it returns a string. I want to call a function that has the same name as the string from the configuration file. configuration.cfg
0
7780
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main...
0
7694
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8021
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8202
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7787
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8065
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5593
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3733
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2213
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.