On 11/22/2012 10:14 AM, Marc Aymerich wrote:
> Hi,
>
> I want to create a method within a class that is able to accept either a 
> class or an instance.
>
> class MyClass(object):
>     @magic_decorator
>     def method(param):
>         # param can be MyClass (cls) or an instance of MyClass (self)
>
> so I can do something like:
>
> instance = MyClass()
>
> MyClass.method()
> instance.method()
>
> I guess the way to go is implementing a custom decorator (@magic_decorator in 
> my example), but, how can I know if the method has been called from the class 
> o from an instance?
>
> Thank you very much!!

I haven't tried it, but how about if you do a @classmethod decorator,
and then just use isinstance(param, MyClass) ?



-- 

DaveA

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

Reply via email to