class or instance method

Xavier Ho contact at xavierho.com
Wed Jun 17 08:24:16 EDT 2009


I'm quite curious as to why you would like it, because:

>>> MyClass
(returns the MyClass class representation)
>>> MyClass()
(returns a instance of the MyClass class)

So, are you just looking for a method that does exactly the above?

Best regards,

Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: contact at xavierho.com
Website: http://xavierho.com/


On Wed, Jun 17, 2009 at 8:39 PM, Bruno Desthuilliers
<bruno.42.desthuilliers at websiteburo.invalid> wrote:

> Paul Johnston a écrit :
>
>> Hi,
>>
>> I would like to have a method that is both a classmethod and an
>> instancemethod. So:
>>
>> class MyClass(object):
>>  @class_or_instance
>>  def myfunc(cls_or_self):
>>    pass
>>
>> The semantics I'd like are:
>> When you call MyClass.myfunc, it gets passed a class
>> When you call MyClass().myfunc, it gets passed an instance
>>
>> I'm sure I've seen some code to do this somewhere, but I can't find it
>> now. Any help appreciated.
>>
>
> IIRC, there's something quite similar in formencode.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090617/eb7b6d44/attachment-0001.html>


More information about the Python-list mailing list