Defining and calling functions in Python

Remco Gerlich scarblac at pino.selwerd.nl
Mon Jan 1 10:23:59 EST 2001


Stein Surland <ssurland at online.no> wrote in comp.lang.python:
> 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++?

It's more interpreted than you think. The function is defined *at runtime*,
def is just a statement, like print. So when you use it beforehand, the def
just hasn't happened yet.

-- 
Remco Gerlich



More information about the Python-list mailing list