Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   How can I get the source file name and current line number insideexecuted C-function (http://www.velocityreviews.com/forums/t341690-how-can-i-get-the-source-file-name-and-current-line-number-insideexecuted-c-function.html)

Marek Prerovsky 02-16-2005 06:37 PM

How can I get the source file name and current line number insideexecuted C-function
 
Hello,

I implemented some Python functions in my C/C++ code. I need to know the Python source file name and line number of just executed
Python command which calls my function.
How can I get this information inside my C/C++ function?

Thanks for any help.

Marek


python 02-16-2005 07:52 PM

Re: How can I get the source file name and current line number inside executed C-function
 


Below is a function to find the caller's file name, line number, etc.
inside Python. Maybe this works for your case.

/Jean Brouwers


- import traceback
-
- 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 = traceback.extract_stack(limit=up+2)
- if f:
- return f[0]
- except:
- if __debug__:
- traceback.print_exc()
- pass
- # running with psyco?
- return ('', 0, '', None)
-
-
- if __name__ == '__main__':
- print caller()



Marek Prerovsky wrote:
> Hello,
>
> I implemented some Python functions in my C/C++ code. I need to know

the Python source file name and line number of just executed
> Python command which calls my function.
> How can I get this information inside my C/C++ function?
>
> Thanks for any help.
>
> Marek




All times are GMT. The time now is 01:38 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57