Adding print-style function calls, and preproc plugins

Gerson Kurz gerson.kurz at t-online.de
Fri Aug 31 00:17:05 EDT 2001


On Fri, 31 Aug 2001 00:33:56 GMT, cjc26 at nospam.cornell.edu (Cliff
Crawford) wrote:

>I haven't seen anyone else mention this yet, but if your socket-cache
>object is a file-like object (i.e. it implements the methods described
>at http://www.python.org/doc/current/lib/bltin-file-objects.html) then
>you can do the following (where "obj" is your cache object):
>
>print >>obj, "stuff to send to the socket"
>print >>obj, "more stuff"
>
>You can use this form of the print statement to print to any file (or
>even to things like StringIO which implement the file object
>interface, but aren't real files) without having to reassign sys.stdout.

HEY! That *is* what I needed. You know, now I can do a simple
search&replace over all the gazillion print statements and make it
work. Ah, Python is great. 



More information about the Python-list mailing list