UnboundLocalError: Local variable 'Tee' referenced before assignment

jschmitt at vmlabs.com jschmitt at vmlabs.com
Wed Dec 6 21:16:37 EST 2000


I'm getting an error message that I don't understand.  I'm using this
handy class that someone kindly on comp.lang.python:

class Tee:
    """
    Think of the unix command-line utility
    """
    def __init__( self, *fileobjects ):
        self.fileobjects = fileobjects

    def write( self, string ):
        for fileobject in self.fileobjects:
            fileobject.write( string )

and I'm using it kind of like this:
reportfile = open( os.path.join( workingdir, "report.txt" ), "w" )
sys.stdout = Tee( reportfile, sys.stdout )    # THIS LINE IS THE PROBLEM
# do some print's here...
del Tee
reportfile.close()

but I get this error message:

UnboundLocalError: Local variable 'Tee' referenced before assignment

Does anyone have a spare clue?  It works the way I expect when I use it
interactively in the python shell.

John


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list