why do I get name not defined error

Diez B. Roggisch deets at nospam.web.de
Wed Feb 18 18:17:00 CET 2009


zaheer.agadi at gmail.com schrieb:
> Hi,
> 
>  I have the following declared in my class, I am trying tp call a
> method defined in the same class
> I am not sure why I am getting name not defined error
> 
>     if options.uploadFile != None :
>         print "This is path", the_rest
>         filePath = the_rest
>         UploadFile(None,filePath)
> 
> def UploadFile(self,path):
>     print "I wil upload now"
>     os.chdir(homeFolder)
>     config = ConfigParser.ConfigParser()
>     .....
> 
> any ideas why the error name UploadFile not defined
> 

Because you need to define things *before* you use them the first time. 
This is not to be confused with forward-declarations, as they are needed 
in C for example - in python you can do


def foo():
    bar()

def bar():
    foo()


(resulting in an endless loop of course)

But you can't do


def foo():
    bar()

foo() # this will fail

def bar():
    foo()



Diez



More information about the Python-list mailing list