Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How can I get the line number ?

Reply
Thread Tools

How can I get the line number ?

 
 
kk
Guest
Posts: n/a
 
      07-24-2009
Hello

I am writing some Python code that runs in another application(has
wrapper functions). Due to lack of debugging I am printing out alot of
outputs and manual messages. I want to be able to create a function
that would let me print the current line number that is called from.
This is not for debugging exceptions it is rather to simplify my debug
messages, at least I can trace my debug messages.

thanks


 
Reply With Quote
 
 
 
 
Maxim Khitrov
Guest
Posts: n/a
 
      07-24-2009
On Fri, Jul 24, 2009 at 2:51 PM, kk<(E-Mail Removed)> wrote:
> Hello
>
> I am writing some Python code that runs in another application(has
> wrapper functions). Due to lack of debugging I am printing out alot of
> outputs and manual messages. I want to be able to create a function
> that would let me print the current line number that is called from.
> This is not for debugging exceptions it is rather to simplify my debug
> messages, at least I can trace my debug messages.
>
> thanks


Modify the following as needed:

from inspect import currentframe, getframeinfo

def caller_info(depth=0):
"""
Get file, line number, and name of the calling function.
"""
if depth < 0:
raise ValueError('invalid stack depth')

caller = frame = currentframe()
try:
for i in xrange(-1, depth):
caller = caller.f_back
if caller is None:
return (None, None, None)

return getframeinfo(caller, 0)[:3]
finally:
del caller, frame

- Max
 
Reply With Quote
 
 
 
 
kk
Guest
Posts: n/a
 
      07-24-2009
Maxim,

Thank you so much. I will try right now.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
number of processors, number of cores, how can I get these numbers? Jekyll C++ 2 04-24-2007 03:58 PM
How can I get the source file name and current line number insideexecuted C-function Marek Prerovsky Python 1 02-16-2005 07:52 PM
Read a file line by line with a maximum number of characters per line Hugo Java 10 10-18-2004 11:42 AM
Can't get line number or compiler error on exception? Eric Gibson ASP .Net 1 08-31-2004 10:41 PM



Advertisments