Why does inherting from object in Python, change they type of the __dict__
when not specifying a parent does not?
I have a simple piece of code that tries to give a convenience to file in
Python.
class File:
def __init__(this, *args):
this._file = file(*args)
def __del__(this):
this._file.close()
def createCallForwarder(method):
return lambda obj,*args: method(obj._file, *args)
_dict = file.__dict__
for (k,v) in zip(_dict.keys(), _dict.values()):
if not (k.startswith('__') and k.endswith('__')):
if v.__class__.__name__ == 'method_descriptor':
File.__dict__[k] = createCallForwarder(v)
# get the repr method
File.__repr__ = createCallForwarder(dict_proxy['__repr__'])
If i change File to inherit from object, it does not let me assign the
methods.
Why is it different?
No comments:
Post a Comment