[IPython-user] 0.4.0 ready for Monday

Fernando Perez fperez at colorado.edu
Tue May 20 10:58:09 CDT 2003


Prabhu Ramachandran wrote:
> Indeed but what stumps me is that this same thing works with
> Python2.2.2 for Gary.  I looked at the version of inspect.py in CVS
> and the getdoc still only looks for an attribute error.  Perhaps
> something deeper is happening?  This is not a serious issue so I'm not
> really worried too much about it.  Thanks.

Good point, I'd forgotten about this (that Gary doesn't see a crash).  Well, 
it will be nice to know what's going on, but I'm not going to worry too much 
about it.

As for the blanket try/except, I'm ok with using those in places where I'm 
only calling  a single line of code I have no control over, such as in this case:

try:
	ds=inspect.getdoc(obj)
except:
	ds=None

Basically I am saying: if getdoc crashes for whatever reason, let's fail 
gracefully by returning the value from a normal failure mode, which is no 
docstring.  I may be hiding bugs in inspect, but since that's not my code, I'd 
rather do that than let them rip through ipython.

Open try/except statements are in most cases a very bad idea.  But I do think 
they serve a very useful purpose in cases like this one. They allow me to 
shield one layer of code from potential problems in other layers I can't fix 
myself.

Cheers,

f.




More information about the IPython-user mailing list