[Tutor] Proxies/Interceptors for file-like objects
Emile van Sebille
emile at fenx.com
Thu Feb 19 01:51:08 CET 2009
Oxymoron wrote:
> I'm trying to intercept one or more methods in file-like objects
Shadowing perhaps?
>>> class open(open):
... def mything(self):
... print "it's my thing"
...
>>> a = open(r'c:\testfile','wb')
>>> a.mything()
it's my thing
>>> a.write("this is a test")
>>> a.flush()
>>> a.close()
>>> open(r'c:\testfile','r').read()
'this is a test'
>>>
Emile
More information about the Tutor
mailing list