Defining and calling functions in Python

Stein Surland ssurland at online.no
Mon Jan 1 10:02:50 EST 2001


I have this function:

def WriteToFile(Outfile, Filecontent):
    Utopened = []
    Utopened = open(Outfile, 'w')
    Utopened.write(string.join(Filecontent,'\n'))
    Utopened.close()

When this function is called with:
     
     WriteToFile('file.txt', 'Some text')

before the function is declared, I get this error message:

Traceback (innermost last):
  File "./RPMParser.py", line 21, in ?
    WriteToFile('file.txt', 'Some text')
NameError: WriteToFile 


But when I move the functioncall after the definition, it works OK. What
am I missing
here? I thought, as Python is an interpreted language, that I didn't
need to "declare in order", as in C++?

Stein
-- 

Stein Surland			  Trying is the first step towards failure
ssurland at online.no			- Homer Simpson
http://home.online.no/~ssurland/



More information about the Python-list mailing list