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
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
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
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):
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
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()
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
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
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
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
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~
--
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
12 matches
Mail list logo