473,404 Members | 2,195 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,404 software developers and data experts.

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

Jul 18 '05 #1
1 5770


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


Jul 18 '05 #2

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

Similar topics

1
by: Henrik Weber | last post by:
Hi. I have tried to add pychecker as an extension to pythonwin. Now I can have pychecker check the source file that is currently open in the editor with a single keypress. If someone is...
5
by: qwweeeit | last post by:
Hi all, I need to limit as much as possible the lenght of a source line, stripping white spaces (except indentation). For example: .. . max_move and AC_RowStack.acceptsCards ( self,...
8
by: Jon Paul Jones | last post by:
For some time now, I have been looking for a build system for ASP.NET that will merge the file based ease of deployment of classic ASP with the type saftey and prebuilt nature of ASP.NET with...
2
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i...
1
by: shapper | last post by:
Hello, I am trying to convert an Asp.Net XML sitemap file in a Google XMl sitemap file using a XSL file using an HttpHandler. Everything seems well in my code but I am getting an error: XML...
3
by: lukefrancomusic | last post by:
I am trying to learn Python. I am working on a simple backup program (code listed below). When using a source directory (the files to be backed up) without spaces in the title, my program works...
19
by: Lee Crabtree | last post by:
Is there a class in the framework that allows me read text from a file in an unbuffered manner? That is, I'd like to be able to read lines in the same manner as StreamReader.ReadLine(), but I also...
4
by: MikeJ | last post by:
make a While loop ofs = TextFileServer("somefile") string srow while (ofs=false) { srow=ofs.getRow(); Console.Writeline(srow); }
6
by: Paul Wilson | last post by:
Hi all, I'd like to be able to do the following to a python source file programmatically: * Read in a source file * Add/Remove/Edit Classes, methods, functions * Add/Remove/Edit Decorators *...
3
by: blunt | last post by:
right the program is nearly complete just a couple of little tweaks and i should have it. The purpose of this program is to write config files for colubrius wireless access points but it's falling...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.