why can't do foo = print ?

Steve Holden sholden at holdenweb.com
Fri Aug 2 12:11:30 EDT 2002


"Shagshag13" <shagshag13 at yahoo.fr> wrote in message
news:aiat1c$12vq6c$1 at ID-146704.news.dfncis.de...
> hello,
>
> i would like to have something like :
>
> if output_is_file:
>     fh = file(filename, 'w')
>     write = fh.write
> else:
>     write = print
>
> ...
>
> for i in something
>     write(i)
>
> how could i do that ? is this possible ? (i can't do "write = print" and
don't understant why)
>

For the same reason you can't do

    define = def

That is to say, the word "print" is a Python keyword, having a special
meaning to the parser/compiler, and therefore unusable as an identifier.

regards
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list