Buffering control in python?

Bengt Richter bokr at oz.net
Sun Oct 13 13:57:21 EDT 2002


On Sat, 12 Oct 2002 20:41:33 -0600, Fernando =?ISO-8859-1?Q?P=E9rez?= <fperez528 at yahoo.com> wrote:

>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?
>
Thanks. I'm hoping to get it a bit more finished before I let it out in the wild.
It's still pretty alpha. If I thought it could put dinner on the table, it
would be on a front burner (to mix metaphors really badly ;-), but so far
it's just evolving when I find I want it do do something new for some purpose.

Regards,
Bengt Richter



More information about the Python-list mailing list