I'm encountering a place where if I use a for loop I can't catch
the error raised by a member.
I've tested python 2.3 and 2.3.1 ( the only ones I had quickly around
) and it's still occuring. Any insight would be appreciated but I
can't figure out why the stand alone call works but for i in doesn't.
I can work around this for now but if someone could please explain
this behavior, it's driving me crazy. I've tried catching everything I
could think of.. Thanks!
#!/bin/env python
import sys, os, ConfigParser
class UGHConfigParser (ConfigParser.C onfigParser):
default_conf = '/tmp/ugh.conf'
def __init__(self, filename=None):
ConfigParser.Co nfigParser.__in it__(self)
if not filename:
filename = self.default_co nf
self.readfp(ope n(filename))
def getNetworkConfi g(self):
"test"
try:
# items = ConfigParser.Co nfigParser.item s(self,'Network ')
items = self.items('Net work')
except UGHConfigParser .NoSectionError :
items = []
except self.NoSectionE rror:
items = []
except ConfigParser.No SectionError:
items = []
except IGiveUp:
items = []
except:
items = []
return items
parser = UGHConfigParser ()
print "this works!"
parser.getNetwo rkConfig()
print "this doesn't!"
for i in parser.getNetwo rkConfig():
print i
Output:
% python ugh.py
this works!
this doesn't!
Traceback (most recent call last):
File "ugh.py", line 41, in ?
for i in parser.getNetwo rkConfig():
File "/usr/lib/python2.3/ConfigParser.py ", line 537, in items
raise NoSectionError( section)
ConfigParser.No SectionError: No section: 'Network'
--
Chris Green <cmg@dok.org>
"I'm beginning to think that my router may be confused."
the error raised by a member.
I've tested python 2.3 and 2.3.1 ( the only ones I had quickly around
) and it's still occuring. Any insight would be appreciated but I
can't figure out why the stand alone call works but for i in doesn't.
I can work around this for now but if someone could please explain
this behavior, it's driving me crazy. I've tried catching everything I
could think of.. Thanks!
#!/bin/env python
import sys, os, ConfigParser
class UGHConfigParser (ConfigParser.C onfigParser):
default_conf = '/tmp/ugh.conf'
def __init__(self, filename=None):
ConfigParser.Co nfigParser.__in it__(self)
if not filename:
filename = self.default_co nf
self.readfp(ope n(filename))
def getNetworkConfi g(self):
"test"
try:
# items = ConfigParser.Co nfigParser.item s(self,'Network ')
items = self.items('Net work')
except UGHConfigParser .NoSectionError :
items = []
except self.NoSectionE rror:
items = []
except ConfigParser.No SectionError:
items = []
except IGiveUp:
items = []
except:
items = []
return items
parser = UGHConfigParser ()
print "this works!"
parser.getNetwo rkConfig()
print "this doesn't!"
for i in parser.getNetwo rkConfig():
print i
Output:
% python ugh.py
this works!
this doesn't!
Traceback (most recent call last):
File "ugh.py", line 41, in ?
for i in parser.getNetwo rkConfig():
File "/usr/lib/python2.3/ConfigParser.py ", line 537, in items
raise NoSectionError( section)
ConfigParser.No SectionError: No section: 'Network'
--
Chris Green <cmg@dok.org>
"I'm beginning to think that my router may be confused."
Comment