binding names doesn't affect the bound objects

Ben Finney bignose+hates-spam at benfinney.id.au
Sat Jul 26 21:34:45 EDT 2008


"D'Arcy J.M. Cain" <darcy at druid.net> writes:

> Hmm.  Are you saying that the following doesn't work?
> 
> $ python
> >>> f = open("test", "w")
> >>> import sys
> >>> sys.stdout = f
> >>> print "test message"
> >>> sys.exit(0)
> $ cat test
> test message
> 
> > In other words, you can't change the object used by the 'print'
> > statement only by re-binding names (which is *all* that is done by
> > the '=' operator).
> 
> Apparently I can.

I admit to not trying any of the above. I was explaining the behaviour
reported by the original poster, without experimenting to see if I
could reproduce the behaviour.

Thanks for being more diligent.

-- 
 \            “All persons, living and dead, are purely coincidental.” |
  `\                                       —_Timequake_, Kurt Vonnegut |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list