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
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
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
From a sequence of numbers, I'm trying to get a list that does something to
even
numbers but leaves untouched the odd ones, say:
[0,1,2,3,4,...] == [100,1,102,3,104,...]
I know that this can be done with an auxiliary function, as follows:
- def filter(n):
... if (n%2 == 0):
...
I'm trying to call an external process to filter some of my data, i.e., I'm
trying to pass some information to the called process, and have this
information
back transformed. I started testing with the linux 'cat' command, in this way:
- import subprocess as sp
- p =
MRAB python at mrabarnett.plus.com writes:
I believe it's waiting for the end of the input, i.e. for the pipe to
close.
Have you tried calling fo.readline() 3 times instead?
yeah! It worked!...
A question remains: what is then the purpose of fo.readlines(...)?
Thanks,
--Sergio
--
J. Cliff Dyer jcd at sdf.lonestar.org writes:
readlines() reads all the lines from the filehandle, but the filehandle
hasn't signalled that it is done writing lines, so fo is waiting until
fi is complete. You either need to keep reading one line at a time, and
manually release control when
I want to use the sign function. When I use it in in-line mode works pretty
well:
: sign(-20)
: -1
However, I wrote the following code in a file, say, pp.py
def tst(x):
s = sign(x)
return(s)
Then I tried to import into my session:
: from pp import *
When I try to use tst,