A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-July/127203.html below:

[Python-Dev] lament for the demise of unbound methods

[Python-Dev] lament for the demise of unbound methods [Python-Dev] lament for the demise of unbound methods"Martin v. Löwis" martin at v.loewis.de
Fri Jul 5 12:26:06 CEST 2013
Am 04.07.13 18:42, schrieb Chris Withers:
> Hi Guido,
> 
> I've bumped into this a couple of times.
> 
> First time was when I wanted to know whether what I had was a
> classmethod, staticmethod or normal method here:
> 
> https://github.com/Simplistix/testfixtures/blob/master/testfixtures/replace.py#L59
> 
> 
> This resulted in having to trawl through __dict__ here:
> 
> https://github.com/Simplistix/testfixtures/blob/master/testfixtures/resolve.py#L17

You could use __getattribute__ instead:

>>> class A:
...   @staticmethod
...   def s():
...     pass
...   @classmethod
...   def c(cl):
...     pass
...   def r(self):
...     pass
...
>>> A.__getattribute__(A,'s')
<staticmethod object at 0x100937828>
>>> A.__getattribute__(A,'c')
<classmethod object at 0x100937860>
>>> A.__getattribute__(A,'r')
<function A.r at 0x100938378>

Regards,
Martin

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4