[print >>] None

Bjorn Pettersen BPettersen at NAREX.com
Tue Oct 23 14:35:21 EDT 2001


> From: Erik Max Francis [mailto:max at alcyone.com] 
> 
> Larry Whitley wrote:
> 
> > def output(self, fout):
> >     print >>fout, self.thing1, self.thing2, self.thing3
> > 
> > In the calling program I say:
> > 
> > object.output( fout ) # print to file
> > object.output( None) # print to standard output
> > 
> > But Python complains that None is a variable that has not been 
> > previously set.  Can someone explain?  I thought None was the empty 
> > object reference.
> > Where have I gone astray?
> 
> It's not clear to me why you expected this work.  print >> 
> None is not the same as plain old print.  print >> x requires 
> an (output) file object, and None isn't one.

It's actually part of the magic of print >> None that it prints to
sys.stdout (yeah, I know, I wasn't in favor of that either ;-)

-- bjorn




More information about the Python-list mailing list