On 01.12.2017 1:19, Greg Ewing wrote:
Ivan Pozdeev via Python-ideas wrote:
I needed to hold an external function reference in an object instance
(if I assigned it to an attribute, it was converted into an instance
method).
No, that only happens to functions stored in *class* attributes,
not instance attributes.
>>> class A:
... pass
...
>>> a = A()
>>>
>>> def f():
... print("I'm just a function")
...
>>> a.x = f
>>> a.x()
I'm just a function
Well, yes, that was a singleton class, so I kept data in the class
object. Now I can simplify the code by only keeping the instance
reference in the class, thank you. (Without knowing this, that bore no
visible benefits.)
--
Regards,
Ivan
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/