Buffering control in python?

Fernando Pérez fperez528 at yahoo.com
Sun Oct 13 04:41:33 CEST 2002


Bengt Richter wrote:

> Yup. Checking with my little watcher makes that easy to verify:
> 
>  >>> from ut.tracewatch import TraceWatch as TW
>  >>> tw = TW()
>  >>> class Proxy(object):
>    [... as above]
> 
>  >>> class AutoFlush(Proxy):
>    [... as above]
> 
>  >>> tw.addwatch('write','#f')
>  >>> tw.on()
>  >>> file = AutoFlush(open("file.txt", "w"))
>  >>> print >> file, "go for it!"
>  --------------------------------------------------------------------
>  File: "<stdin>"
>  Line [scope] C:all, R:eturn eX:cept S:tack N:ew M:od E:quiv U:nbound
>  ---- ------- -------------------------------------------------------
>     2 [write]:           C: write(self=<__main__.AutoFlush object at
>     0x007D6310>, data='go for it!')
>  LOOK MA! I'M FLUSHING! :)
>     5 [write]:           R: write(...) => None
>     2 [write]:           C: write(self=<__main__.AutoFlush object at
>     0x007D6310>, data='\n')
>  LOOK MA! I'M FLUSHING! :)
>     5 [write]:           R: write(...) => None
> 

And this nifty watcher would be found where for us mere mortals, pray tell?

That looks _very_ useful in a number of situations. Care to share it?

Cheers,

f.



More information about the Python-list mailing list