How to validate the __init__ parameters
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon Jan 4 14:51:53 EST 2010
En Mon, 04 Jan 2010 15:17:04 -0300, Albert van der Horst
<albert at spenarnc.xs4all.nl> escribió:
> This triggers a question: I can see the traceback, but it
> would be much more valuable, if I could see the arguments
> passed to the functions. Is there a tool?
Yes, the cgitb module [1]. Despite its name it's a general purpose module.
This code:
<code>
import cgitb
cgitb.enable(format="text")
spam = []
def a(x, y):
"""This is function a"""
z = x+y
return b(z)
def b(z, n=3):
"""This is function b"""
return c(foo=z*n)
def c(foo=0, bar=1):
"""This is function c"""
baz = foo+bar
spam.somenamethatdoesnotexist(foo+bar)
a(10, 20)
<code>
generates this error message:
A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurr
ed.
d:\temp\test_traceback.py in <module>()
19 baz = foo+bar
20 spam.somenamethatdoesnotexist(foo+bar)
21
22
23 a(10, 20)
a = <function a at 0x00BFEBB0>
d:\temp\test_traceback.py in a(x=10, y=20)
7 """This is function a"""
8 z = x+y
9 return b(z)
10
11
global b = <function b at 0x00BFEBF0>
z = 30
d:\temp\test_traceback.py in b(z=30, n=3)
12 def b(z, n=3):
13 """This is function b"""
14 return c(foo=z*n)
15
16
global c = <function c at 0x00BFEC30>
foo undefined
z = 30
n = 3
d:\temp\test_traceback.py in c(foo=90, bar=1)
18 """This is function c"""
19 baz = foo+bar
20 spam.somenamethatdoesnotexist(foo+bar)
21
22
global spam = []
spam.somenamethatdoesnotexist undefined
foo = 90
bar = 1
<type 'exceptions.AttributeError'>: 'list' object has no attribu
te 'somenamethatdoesnotexist'
__class__ = <type 'exceptions.AttributeError'>
__dict__ = {}
__doc__ = 'Attribute not found.'
... more exception attributes ...
The above is a description of an error in a Python program. Her
e is
the original traceback:
Traceback (most recent call last):
File "d:\temp\test_traceback.py", line 23, in <module>
a(10, 20)
File "d:\temp\test_traceback.py", line 9, in a
return b(z)
File "d:\temp\test_traceback.py", line 14, in b
return c(foo=z*n)
File "d:\temp\test_traceback.py", line 20, in c
spam.somenamethatdoesnotexist(foo+bar)
AttributeError: 'list' object has no attribute 'somenamethatdoes
notexist'
[1] http://docs.python.org/library/cgitb.html
--
Gabriel Genellina
More information about the Python-list
mailing list