Adding functions to classes after definition

G

Gerard Brunick

Consider: A).... pass
........ print args
.... (<__main__.C object at 0x04A51170>,)

And B)
(<__main__.C object at 0x04A51290>,)

I don't understand A). It is my vague understanding, that methods are
really properties that handle binding on attribute access, so B) should
be the "right" way to add a method to a class after definition. Why does
A show up as a method? Shouldn't it still just be a function? Certainly
when you define a class, there is some magic in the __new__ method that
turns functions in the initial dictionary into methods, but does this still
happen for all setattr after that? Is is possible to set a class attribute
equal to a regular (types.FunctionType) function?

Any references that discuss these issues would be greatly appreciated.

Thanks,
Gerard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top