Larry Whitley ldw at
Wed Oct 24 17:07:05 CEST 2001

Here's the traceback requested:

u:\trc45\pecos\ c:\projects\pecos\traces\ ('',
.dat', 'crusader091101.a3.txt')
Traceback (most recent call last):
  File "C:\Projects\Pecos\Traces\", line 372, in ?
  File "C:\Projects\Pecos\Traces\", line 365, in main
    process( localPath + files[1], localPath + files[2] ) # process the file
  File "C:\Projects\Pecos\Traces\", line 336, in process
    pc.runningReport( None, riostream ) # to stdout
UnboundLocalError: local variable 'None' referenced before assignment

Here's the relevant section of code in the neighborhood of the error:
            if pc.endCond != "":
                riostream =
                pc.runningReport( fout, riostream ) # to file
                pc.runningReport( None, riostream ) # to stdout

The method runningReport() looks like this:
    def runningReport(self, fout, riostream):
        print >>fout, "%8d" % self.startCycn, "%8d" % self.endCycn, "%6d" %
(self.endCycn - self.startCycn), \
              "%8s" % self.command, "%10x" % self.startAddr, "%10x" %
self.endAddr, "%4d" % self.nBytes, \
              "%8s" % self.endCond, riostream

My idea was to setup the method to print to file and by substituting None
for the file object, let the same method send the output to standard out.

Thanks for the help,

"Larry Whitley" <ldw at> wrote in message
news:9r4b95$suc$1 at
> 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
> 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