Michael Lerner mlerner at
Tue Oct 23 20:21:32 CEST 2001

I think there's something else going on here .. I just tried it and it
worked for me:

>>> class boop:
...     def __init__(self):
...             self.thing1 = "a"
...             self.thing2 = "b"
...             self.thing3 = "c"
...     def output(self,fout):
...             print >> fout, self.thing1, self.thing2, self.thing3
>>> foo = boop()
>>> foo.output(None)
a b c

dunno if that helps or not ..

(of course, if you make silly mistakes like I do, you might accidentally
type "none" instead of "None" .. that'll fail with a NameError)


Larry Whitley <ldw at> wrote:
> I want to have a methode of a class that will take the argument of a file
> object that has previously been opened for write and be able to call it,
> directing it's output to a file, or directing the output to standard output.

> 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?

> Larry

More information about the Python-list mailing list