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 stdin, line 1, in module File tst.py, line

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 julioser...@gmail.com

Re: using identifiers before they are defined

2012-06-12 Thread Emile van Sebille
On 6/12/2012 10:53 AM Julio Sergio said... snip 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 stdin, line 1, inmodule

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 Julio Sergio
Jose H. Martinez josehmartinezz at 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

Re: using identifiers before they are defined

2012-06-12 Thread Jerry Hill
On Tue, Jun 12, 2012 at 2:33 PM, Julio Sergio julioser...@gmail.com 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()

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

Re: using identifiers before they are defined

2012-06-12 Thread Ethan Furman
Julio Sergio wrote: Jose H. Martinez josehmartinezz at 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

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 et...@stoneleaf.us wrote: Julio Sergio wrote: Jose H. Martinez josehmartinezz at gmail.com writes: You should define the function first and then call it. def

Re: using identifiers before they are defined

2012-06-12 Thread Julio Sergio
Ethan Furman ethan at 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 Ethan Furman
Julio Sergio wrote: Ethan Furman ethan at 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~ --

Re: using identifiers before they are defined

2012-06-12 Thread Ben Finney
Julio Sergio julioser...@gmail.com 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