instance method questions

D

Danny

howdy,

I have created an instance method for an object using new.instancemethod. It
works great. Now the questions are:

1) how do I dynamically inspect an object to determine if it has an instance
method? (there is a class method with the same name)

2) how do I dynamically delete the instance method?

thanks,
Danny
 
F

Frederick Polgardy

1) how do I dynamically inspect an object to determine if it has an instance
method? (there is a class method with the same name)

class Foo:
def foo(self):
pass

x = Foo()

import types
 
P

Peter Otten

Danny said:
I have created an instance method for an object using new.instancemethod.
It works great. Now the questions are:

1) how do I dynamically inspect an object to determine if it has an
instance method? (there is a class method with the same name)

Why would you want to do that?

Here is a way that relies on an implementation detail of current CPython:
.... def foo(self): pass
.... def __init__(self):
.... import new
.... def bar(self): pass
.... self.foo = new.instancemethod(bar, self)
....False

This alternative is a little less subtle:
False

Peter
 

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,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top