why do I get name not defined error

Z

zaheer.agadi

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

Thnaks
 
D

Diez B. Roggisch

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
 
P

Peter Otten

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

Assuming this is part of a method

def method(self):
if options.uploadFile != None :
print "This is path", the_rest
filePath = the_rest
UploadFile(None,filePath)

you have to change the above line to

self.UploadFile(filePath)


Now consider reading a tutorial before you proceed.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top