Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

get line number and filename in a source file

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


pengyu.ut at gmail

Nov 24, 2009, 9:47 PM

Post #1 of 4 (1162 views)
Permalink
get line number and filename in a source file

__LINE__ __FILE__ in C++ can give the current line number and
filename. Is there a similar thing in python that can give me the
current line number and filename?

Is there a similar thing to __PRETTY_FUNCTION__ (also from C++)?
--
http://mail.python.org/mailman/listinfo/python-list


clp2 at rebertia

Nov 24, 2009, 10:01 PM

Post #2 of 4 (1150 views)
Permalink
Re: get line number and filename in a source file [In reply to]

On Tue, Nov 24, 2009 at 9:47 PM, Peng Yu <pengyu.ut [at] gmail> wrote:
> __LINE__ __FILE__ in C++ can give the current line number and
> filename. Is there a similar thing in python that can give me the
> current line number and filename?

import inspect
filename, linenum, funcname = inspect.getframeinfo(inspect.currentframe())[:3]

Cheers,
Chris
--
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


rami.chowdhury at gmail

Nov 24, 2009, 10:04 PM

Post #3 of 4 (1156 views)
Permalink
Re: get line number and filename in a source file [In reply to]

On Nov 24, 2009, at 21:47 , Peng Yu wrote:

> __LINE__ __FILE__ in C++ can give the current line number and
> filename. Is there a similar thing in python that can give me the
> current line number and filename?
> Is there a similar thing to __PRETTY_FUNCTION__ (also from C++)?

What do you want to use them for?

> --
> http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


davea at ieee

Nov 24, 2009, 10:58 PM

Post #4 of 4 (1149 views)
Permalink
Re: get line number and filename in a source file [In reply to]

Peng Yu wrote:
> __LINE__ __FILE__ in C++ can give the current line number and
> filename. Is there a similar thing in python that can give me the
> current line number and filename?
>
> Is there a similar thing to __PRETTY_FUNCTION__ (also from C++)?
>
>
mod.__name__ gives the module name, and mod.__file__ gives the full
path to the given module. Or if you need those for the current module,
just leave off the prefix.

For line number information, you probably can get it from the inspect
module, but I don't have any direct experience. I do have the following
untested line
in my notes:
inspect.getframeinfo(inspect.currentframe()).function)

DaveA



--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.