[Tutor] Proxies/Interceptors for file-like objects

Oxymoron moron.oxy at gmail.com
Thu Feb 19 00:43:35 CET 2009


Hello,

I'm trying to intercept one or more methods in file-like objects (in
this particular case just sys.stdin really), essentially I need a
decorator/proxy implemented.

What's the idiomatic way to do this? Since file objects do not have a
base class(?), would I need to implement all methods to delegate down
to my wrapped object, or can I use a special method to define default
behaviour?

I came across http://pypi.python.org/pypi/filelike/0.3.2 on googling.
It seems a little overkill for what I want to do however, but it does
define a base class.

Thanks.

-- Kamal


More information about the Tutor mailing list