Re: using identifiers before they are defined

2012-06-12 Thread Ben Finney
Julio Sergio writes: > Suppose I have to define two functions, aa, and, bb that are designed > to call each other: > > def aa(): > ... > ... a call of bb() somewhere in the body of aa > ... > > def bb(): > ... > ... a call of aa() somewhere in the body of bb > ..

Re: using identifiers before they are defined

2012-06-12 Thread Ethan Furman
Julio Sergio wrote: Ethan Furman stoneleaf.us> writes: No. The reply from MRAB explains this. ~Ethan~ Thanks, you're right! I was confusing statemens with declarations. Yeah, it took me a while to get that straight as well. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-lis

Re: using identifiers before they are defined

2012-06-12 Thread Julio Sergio
Ethan Furman stoneleaf.us> writes: > > > No. The reply from MRAB explains this. > > ~Ethan~ > Thanks, you're right! I was confusing statemens with declarations. -- http://mail.python.org/mailman/listinfo/python-list

Re: using identifiers before they are defined

2012-06-12 Thread Jose H. Martinez
Seems like what you need is from othermodule import bb def aa(): bb() On Tue, Jun 12, 2012 at 2:51 PM, Ethan Furman wrote: > Julio Sergio wrote: > >> Jose H. Martinez gmail.com> writes: >> >> >>> You should define the function first and then call it. >>> >>> >>> def something(i): r

Re: using identifiers before they are defined

2012-06-12 Thread Ethan Furman
Julio Sergio wrote: Jose H. Martinez gmail.com> writes: You should define the function first and then call it. def something(i): return i a = something(5) If you want a reference to the function somewhere else you can do this: I know that. That was what I meant by "changing the

Re: using identifiers before they are defined

2012-06-12 Thread Evan Driscoll
On 01/-10/-28163 01:59 PM, Julio Sergio wrote: I know that changing the order of the definitions will work, however there are situations in which referring to an identifier before it is defined is necessary, e.g., in crossed recursion. Mutual recursion isn't a problem: the following strange exp

Re: using identifiers before they are defined

2012-06-12 Thread Jerry Hill
On Tue, Jun 12, 2012 at 2:33 PM, Julio Sergio wrote: > Suppose I have to define two functions, aa, and, bb that are designed to call > each other: > >  def aa(): >     ... >     ... a call of bb() somewhere in the body of aa >     ... > >  def bb(): >     ... >     ... a call of aa() somewhere in

Re: using identifiers before they are defined

2012-06-12 Thread Julio Sergio
Jose H. Martinez gmail.com> writes: > > > You should define the function first and then call it. > > >  def something(i):     return i > > > a = something(5) > > > If you want a reference to the function somewhere else you can do this: > I know that. That was what I meant by "changing t

Re: using identifiers before they are defined

2012-06-12 Thread MRAB
On 12/06/2012 18:53, Julio Sergio wrote: I'm puzzled with the following example, which is intended to be a part of a module, say "tst.py": a = something(5) def something(i): return i When I try: ->>> import tst The interpreter cries out: Traceback (most recent call last):

Re: using identifiers before they are defined

2012-06-12 Thread Emile van Sebille
On 6/12/2012 10:53 AM Julio Sergio said... So I modified my module: global something a = something(5) def something(i): return i And this was the answer I got from the interpreter: ->>> import tst Traceback (most recent call last): File "", line 1, in File "tst.py

Re: using identifiers before they are defined

2012-06-12 Thread Jose H. Martinez
You should define the function first and then call it. def something(i): return i a = something(5) If you want a reference to the function somewhere else you can do this: global alias = something print alias(i) On Tue, Jun 12, 2012 at 1:53 PM, Julio Sergio wrote: > I'm puzzled with

using identifiers before they are defined

2012-06-12 Thread Julio Sergio
I'm puzzled with the following example, which is intended to be a part of a module, say "tst.py": a = something(5) def something(i): return i When I try: ->>> import tst The interpreter cries out: Traceback (most recent call last): File "", line 1, in File "tst.py", line 11