None

Larry Whitley ldw at us.ibm.com
Wed Oct 24 11:07:05 EDT 2001


Here's the traceback requested:

C:\Projects\Pecos\Traces>analyze3
u:\trc45\pecos\ c:\projects\pecos\traces\ ('crusader091101.zip',
'crusader091101
.dat', 'crusader091101.a3.txt')
Traceback (most recent call last):
  File "C:\Projects\Pecos\Traces\analyze3.py", line 372, in ?
    main()
  File "C:\Projects\Pecos\Traces\analyze3.py", line 365, in main
    process( localPath + files[1], localPath + files[2] ) # process the file
  File "C:\Projects\Pecos\Traces\analyze3.py", 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 != "":
                pc.summarizeData()
                riostream = pc.rio()
                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



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