why can't do foo = print ?

Jonathan Hogg jonathan at onegoodidea.com
Sat Aug 3 05:13:46 EDT 2002


On 2/8/2002 21:00, in article 4qB29.7601$672.1692266 at news20.bellglobal.com,
"Steve Menard" <steve.menard at polyester.com> wrote:

> you may realize that "print A" is just a shortcust for
>   sys.__stdout__.write(A)
>   sys.__stdout__.write("\n")

I believe it's actually a shortcut for:

    sys.stdout.write(A)
    sys.stdout.write("\n")

If you're using a recent Python, you might also look at:

    if output_is_file:
        output = file( filename, 'w' )
    else:
        output = sys.stdout

    for i in something
        print >> output, i

which I think reads better and makes it very explicit what is going on.

-if-it's-hard-to-type-then-the-lib-is-trying-to-tell-you-something-ly y'rs,

Jonathan




More information about the Python-list mailing list