niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » python
ConfigParser: what read('non-existent-filename') returns in 2.3.x?
Post new topic   Reply to topic Page 1 of 1 [5 Posts] View previous topic :: View next topic
Author Message
Danil Dotsenko
*nix forums beginner


Joined: 20 Jul 2006
Posts: 3

PostPosted: Thu Jul 20, 2006 5:50 pm    Post subject: ConfigParser: what read('non-existent-filename') returns in 2.3.x? Reply with quote

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.read('non-existent-filename') returns [] in 2.4.x

One user with 2.3.x reported an error stemming from my use of
len(cfgObject.read('potentially-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:
Quote:
import ConfigParser
cfg = ConfigParser.ConfigParser()
a = cfg.read('adsfasfdasfd')
a, len(a), type(a)
([], 0, <type 'list'>)


Thx in advance.

Daniel.
Back to top
Chris Lambacher
*nix forums addict


Joined: 16 May 2005
Posts: 65

PostPosted: Thu Jul 20, 2006 7:30 pm    Post subject: Re: ConfigParser: what read('non-existent-filename') returns in 2.3.x? Reply with quote

On Thu, Jul 20, 2006 at 10:50:40AM -0700, Danil Dotsenko wrote:
Quote:
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.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.
Quote:

One user with 2.3.x reported an error stemming from my use of
len(cfgObject.read('potentially-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.
Quote:

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

Thx in advance.

Daniel.
--
http://mail.python.org/mailman/listinfo/python-list
Back to top
Danil Dotsenko
*nix forums beginner


Joined: 20 Jul 2006
Posts: 3

PostPosted: Thu Jul 20, 2006 9:01 pm    Post subject: Re: ConfigParser: what read('non-existent-filename') returns in 2.3.x? Reply with quote

Chris Lambacher wrote:
Quote:
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.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/RawConfigParser-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.

Quote:
import ConfigParser
cfg = ConfigParser.ConfigParser()
a = cfg.read('adsfasfdasfd')
a, len(a), type(a)
([], 0, <type 'list'>)

Thx in advance.
Back to top
Danil Dotsenko
*nix forums beginner


Joined: 20 Jul 2006
Posts: 3

PostPosted: Thu Jul 20, 2006 9:19 pm    Post subject: Re: ConfigParser: what read('non-existent-filename') returns in 2.3.x? Reply with quote

Danil Dotsenko wrote:

Quote:
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.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/RawConfigParser-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.ConfigParser()
a = cfg.read('adsfasfdasfd')
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.ConfigParser()
 >>> a = cfg.read('adsfasfdasfd')
 >>> a
 >>> type(a)
<type 'NoneType'>
 >>> len(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: len() of unsized object
 >>>  
Back to top
Chris Lambacher
*nix forums addict


Joined: 16 May 2005
Posts: 65

PostPosted: Fri Jul 21, 2006 1:57 pm    Post subject: Re: ConfigParser: what read('non-existent-filename') returns in 2.3.x? Reply with quote

On Thu, Jul 20, 2006 at 02:01:08PM -0700, Danil Dotsenko wrote:
Quote:
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.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/RawConfigParser-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.cfg']) == []

since config.read does not explicitly return anything, and therefore you get
None.
Quote:

import ConfigParser
cfg = ConfigParser.ConfigParser()
a = cfg.read('adsfasfdasfd')
a, len(a), type(a)
([], 0, <type 'list'>)

Thx in advance.



--
http://mail.python.org/mailman/listinfo/python-list
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [5 Posts] View previous topic :: View next topic
The time now is Sat Nov 22, 2008 9:11 pm | All times are GMT
navigation Forum index » Programming » python
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts CGI.pm and lost carriage returns Joseph Czapski Perl 21 Thu Jul 20, 2006 3:52 pm
No new posts socket read modifies third parameter after the call: Very... jainarunk@gmail.com networking 1 Thu Jul 20, 2006 3:47 pm
No new posts ksh tab filename completion Sashi shell 2 Wed Jul 19, 2006 9:24 pm
No new posts ===Welcome to comp.lang.c++! Read this first. Shiva C++ 0 Wed Jul 19, 2006 4:29 pm
No new posts multiple InnoDB read-only server instances on same file s... pradhuman jhala MySQL 1 Tue Jul 18, 2006 11:48 pm

Auto Loans | Unique MySpace Layouts | Mortgage | Free Ringtones | Remortgages
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 10.5262s ][ Queries: 16 (10.3377s) ][ GZIP on - Debug on ]