Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7208

Re: Function call arguments in stack trace?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'arguments': 0.05; 'attributes': 0.05; 'exception,': 0.07; 'names.': 0.07; 'raised': 0.07; 'tue': 0.07; 'python': 0.08; 'attribute': 0.09; 'foo': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:Function': 0.09; 'undefined': 0.09; 'output': 0.11; 'def': 0.12; 'exception': 0.12; 'debugging': 0.14; '"""this': 0.16; '...]': 0.16; 'baz': 0.16; 'docstring': 0.16; 'from:addr:yahoo.com.ar': 0.16; 'occurred.': 0.16; 'read:': 0.16; 'stack': 0.16; 'traceback': 0.16; '(most': 0.16; 'tue,': 0.17; 'occurred': 0.19; 'script.': 0.19; 'trace': 0.19; 'last):': 0.23; 'somehow': 0.23; '"this': 0.25; 'function': 0.25; 'modules': 0.26; 'object': 0.26; 'problem': 0.28; 'subject:?': 0.29; 'import': 0.29; 'instead': 0.29; 'module': 0.30; 'header:X-Complaints-To:1': 0.32; 'does': 0.33; 'to:addr:python-list': 0.33; 'file': 0.34; 'example,': 0.35; 'header:User-Agent:1': 0.35; 'test': 0.35; 'similar': 0.37; 'despite': 0.37; 'sequence': 0.37; 'third-party': 0.37; 'received:org': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'skip:s 20': 0.39; 'called': 0.39; 'header:Mime- Version:1': 0.39; 'to:addr:python.org': 0.39; 'order': 0.62; 'here': 0.66; 'offer': 0.71; 'received:190': 0.74; '-0300,': 0.84; 'cgitb': 0.84; 'genellina': 0.84; 'gabriel': 0.91; 'subject:call': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From "Gabriel Genellina" <gagsl-py2@yahoo.com.ar>
Subject Re: Function call arguments in stack trace?
Date Tue, 07 Jun 2011 23:45:15 -0300
References <9d344c45-8017-4c80-9a17-bc7accd81047@l26g2000yqm.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=iso-8859-1; format=flowed; delsp=yes
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host 190.2.4.25
User-Agent Opera Mail/11.11 (Win32)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12.1307500925.11593.python-list@python.org> (permalink)
Lines 117
NNTP-Posting-Host 82.94.164.166
X-Trace 1307500925 news.xs4all.nl 49180 [::ffff:82.94.164.166]:48798
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7208

Show key headers only | View raw


En Tue, 07 Jun 2011 15:09:54 -0300, Dun Peal <dunpealer@gmail.com>  
escribió:

> In a stack trace, is it possible to somehow get the arguments with
> which each function was called?
>
> So for example, if function `foo` in module `bar` was called with
> arguments `(1, [2])` when it raised an exception, then instead of:
>
>     Traceback (most recent call last):
>       File "bar.py", line 123, in foo
>         build_rpms()
>
> The stack trace would read:
>
>     Traceback (most recent call last):
>       File "bar.py", line 123, in foo(1, [2])
>         build_rpms()
>
> This would save a lot of debugging time!

The cgitb module does exactly that; some third-party modules offer similar  
functionality, but I don't remember any names.
Despite its name, cgitb works with any script.

Given this test script:

# begin test_traceback.py
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.

   Its docstring is longer."""

   if n!=3:
     just(to_consume_space)

   w = c(foo=z*n)

   return w


def c(foo=0, bar=1):
   "This is function c"
   baz = foo+bar
   spam.somenamethatdoesnotexist(foo+bar)
   anotherglobal("thatdoesnotexisteither")

a(10, 20)
# end test_traceback.py

the output is:


AttributeError
Python 3.2: d:\apps\Python32\python.exe
Tue Jun  7 23:36:36 2011

A problem occurred in a Python script.  Here is the sequence of
function calls leading up to the error, in the order they occurred.

  D:\TEMP\test_traceback.py in <module>()
    27   baz = foo+bar
    28   spam.somenamethatdoesnotexist(foo+bar)
    29   anotherglobal("thatdoesnotexisteither")
    30
    31 a(10, 20)
a = <function a>

  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>
z = 30

  D:\TEMP\test_traceback.py in b(z=30, n=3)
    18     just(to_consume_space)
    19
    20   w = c(foo=z*n)
    21
    22   return w
w undefined
global c = <function c>
foo undefined
z = 30
n = 3

  D:\TEMP\test_traceback.py in c(foo=90, bar=1)
    26   "This is function c"
    27   baz = foo+bar
    28   spam.somenamethatdoesnotexist(foo+bar)
    29   anotherglobal("thatdoesnotexisteither")
    30
global spam = []
spam.somenamethatdoesnotexist undefined
foo = 90
bar = 1
AttributeError: 'list' object has no attribute 'somenamethatdoesnotexist'
    [... exception attributes ...]
    [... original traceback ...]

-- 
Gabriel Genellina

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Function call arguments in stack trace? Dun Peal <dunpealer@gmail.com> - 2011-06-07 11:09 -0700
  Re: Function call arguments in stack trace? Neil Cerutti <neilc@norwich.edu> - 2011-06-07 18:23 +0000
    Re: Function call arguments in stack trace? Dun Peal <dunpealer@gmail.com> - 2011-06-07 12:31 -0700
      Re: Function call arguments in stack trace? Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-07 13:52 -0600
      Re: Function call arguments in stack trace? Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2011-06-07 22:01 +0200
      Re: Function call arguments in stack trace? Neil Cerutti <neilc@norwich.edu> - 2011-06-07 20:29 +0000
  Re: Function call arguments in stack trace? "Gabriel Genellina" <gagsl-py2@yahoo.com.ar> - 2011-06-07 23:45 -0300

csiph-web