[Tutor] Equivalent of PHP's __FUNCTION__ ?
Kent Johnson
kent37 at tds.net
Thu Dec 2 19:42:09 CET 2004
Here is one way to do it, based on this Python Cookbook recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66062
def debug(msg):
import sys
frame = sys._getframe(1)
name = frame.f_code.co_name
line_number = frame.f_lineno
filename = frame.f_code.co_filename
return 'File "%s", line %d, in %s: %s' % (filename, line_number, name, msg)
def test():
print debug("Invalid arguments")
test()
Kent
Mohamed Lrhazi wrote:
> Hello all,
>
> In php one can produce nice debugging and logging use code like:
> print __FUNCTION__ . ": Invalid arguments\n";
>
> __FUNCTION__ will be replaced by the name of the function to which that
> line belongs, same with __LINE__ and __FILE__ I believe.
>
> How do I get the current method's name? and class?
>
> Thanks.
>
> Mohamed~
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list