473,326 Members | 2,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Determining caller's file and line number

Is there any way to determine the file and line number (if any) of a
method's invocation from within its body?

Many Thanks in advance,

Dave
--
David Abrahams
Boost Consulting
http://www.boost-consulting.com
Jul 18 '05 #1
2 2972

Here is one example:

<pre>

from traceback import extract_stack as tb_extract_stack,

def caller(up=0):
'''Get file name, line number, function name and
source text of the caller's caller as 4-tuple:
(file, line, func, text).

The optional argument 'up' allows retrieval of
a caller further back up into the call stack.

Note, the source text may be None and function
name may be '?' in the returned result. In
Python 2.3+ the file name may be an absolute
path.
'''
try: # just get a few frames
f = tb_extract_stack(limit=up+2)
if f:
return f[0]
except:
pass
# running with psyco?
return ('', 0, '', None)

</pre>

/Jean Brouwers
ProphICy Semiconductor, Inc.

In article <8a**************************@posting.google.com >, David
Abrahams <da**@boost-consulting.com> wrote:
Is there any way to determine the file and line number (if any) of a
method's invocation from within its body?

Many Thanks in advance,

Dave
--
David Abrahams
Boost Consulting
http://www.boost-consulting.com

Jul 18 '05 #2
Jean Brouwers <mr*****@comcast.net> wrote in message news:<230620041639365943%mr*****@comcast.net>...
Here is one example:


Fantastic! Thank you so much!

--
David Abrahams
Boost Consulting
http://www.boost-consulting.com
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: ivan_oj28 | last post by:
Hi, I am developing an application where I need to read the caller id from an incoming call. The only info (for now) I need is the caller id info, so that I can display the propper caller info on...
66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
2
by: Luca | last post by:
I have the following problem: I'm developing a system where there are some processes that communicate each other via message queues; the message one process can send to another process is as...
12
by: johny smith | last post by:
I am trying to figure out a way to print the address of what called a certain function once inside the function. I am assuming that this information is on the stack somewhere. But can someone...
20
by: 2pac | last post by:
in this scenario foo1 ---calls---> foo2 is it possible for me to print out - when the control is within foo2 - the caller of foo2 the information is obviously there in the stack - am wondering...
3
by: Fred Nelson | last post by:
I'm devloping a Web Application in VB.NET. In my web.config file I have specified that untrapped errors are to be sent to the page "errorpage.aspx". This is working fine - if an untrapped error...
5
by: Bob Day | last post by:
VS 2003, vb.net... Is there a way to determine the line number currently executing in your code, so you can log this line number information (e.g. via trace)? Thanks! Bob Day
14
by: googler | last post by:
Is there any C library function that returns the size of a given file? Otherwise, is there a way in which file size can be determined in a C program? I need to get this for both Linux and Windows...
2
by: JohnR | last post by:
Hi, I'm looking for some advice and guidance. I have a program in vb.net and I know that when it's run and the pdb file is available that the exception will contain the line number of the error. ...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.