pondering about the essence of types in python
Steven Bethard
steven.bethard at gmail.com
Sun Mar 26 12:29:29 EST 2006
gangesmaster wrote:
> i dont think it's possible, to create proxy classes, but even if i did,
> calling remote methods with a `self` that is not an instance of the
> remote class would blow up.
I don't understand you here. Why can't you just do something like:
>>> class RemoteClass(object):
... def __init__(self, name):
... self.name = name
... def __repr__(self):
... return '%s(name=%s)' % (type(self).__name__, self.name)
...
>>> rc = RemoteClass('foo')
>>> rc
RemoteClass(name=foo)
>>> class ProxyClass(object):
... def __init__(self, name):
... self.remote = RemoteClass(name)
... def __repr__(self):
... return repr(self.remote)
...
>>> pc = ProxyClass('foo')
>>> pc
RemoteClass(name=foo)
Note that when I call methods on the remote class, I don't pass them an
instance of the proxy class -- I pass them an instance of the
appropriate, RemoteClass type. Of course my code is simplified because
I'm not actually doing something remote, but assuming things get, say,
pickled and unpickled appropriately, I'm not sure I understand why the
above won't work.
Could you give some more details?
STeVe
More information about the Python-list
mailing list