>
> Python translates object.method() to method(object).

Well, yes and no. "Yes" in the sense that instance methods are internally
implemented equivalently to a free method which takes an instance as the
first parameter. "No" in the sense that from a namespace and user
perspective there typically isn't a crossover:

>>> class TestClass:
    def __init__(self, name):
        self.name = name
    def say(self):
        print("I'm TestClass",self.name)

>>> def recite(test_class):
    test_class.say()

>>> t = TestClass("Bob")
>>> t.say()
I'm TestClass Bob
>>> recite(t)
I'm TestClass Bob
>>> t.recite()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'TestClass' object has no attribute 'recite'

(As the `recite` function is in the local namespace, not in the TestClass
namespace, `t.recite()` can't find it.)

While, due to the equivalence between free functions and member functions,
you can certainly inject such a free function into the class:

>>> TestClass.recite = recite
>>> t.recite()
I'm TestClass Bob

such an injection isn't universally what one sees in typical Python
programs, as anyone who's tried to do a `mylist.len()` can attest. Doing
such an injection dependent on module imports is much rarer, and certainly
not the expected "standard" behavior in Python. (It's certainly not
automatic in Python, if that was what you were trying to imply.)

Regards,
-Rocco
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to