about functions question

Arnaud Delobelle arnodel at googlemail.com
Thu Oct 25 05:30:29 EDT 2007


On Oct 25, 7:28 am, NoName <zaz... at gmail.com> wrote:
> I try it:
>
> def b():
>   ...
>   a()
>   ...
>
> def a():
>   ...
>   b()
>   ...
>
> b()
> it's not work.

Probably all those dots!

> Is it possible pre-define function like in c++ or place functions code
> after main block?

Python binds names to objects dynamically: this means that when a() is
compiled, the "b()" line in its definition is compiled to something
that says "look for the object currently bound to the name 'b' in the
global dictionary, and execute the __call__ method of that object with
no arguments".  It doesn't make any difference what object 'b' is
bound to at this time.

HTH

--
Arnaud





More information about the Python-list mailing list