Re: get line number and filename in a source file
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
Re: get line number and filename in a source file
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
Re: get line number and filename in a source file
On Tue, Nov 24, 2009 at 9:47 PM, 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? import inspect filename, linenum, funcname = inspect.getframeinfo(inspect.currentframe())[:3] Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
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