[Tutor] print method name

James Reynolds eire1130 at gmail.com
Thu Dec 8 16:15:05 CET 2011


On Thu, Dec 8, 2011 at 9:49 AM, rail shafigulin
<rail.shafigulin at gmail.com>wrote:

> i created a class and in some instances when i use it call some of its
> methods i need to print a method name. the online search did produce some
> results but none of them seem to work for me. for example one of them said
> just to use __name__ or func_name but it didn't work for me. i'm using
> python 3.1.1
>
> any help is appreciated.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
Can you show the code?

This works for me:

class A(object):
    def __init__(self):
        pass

    def addr(self,a,b):
        return a + b

a = A()
print a.addr.__name__

>>addr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111208/e2d2b7dd/attachment.html>


More information about the Tutor mailing list