Hi all, I tried to use the home-made function (available at http://www.scipy.org/Cookbook/InputOutput) to read an array from the file topo-28.xohis (See attachment for details). If I run the script (xy.py) I get python -i xy.py Traceback (most recent call last): File "xy.py", line 47, in ? data = readArray("topo-28.xohis") File "xy.py", line 35, in readArray items = split(stripped_line) TypeError: split() takes at least 2 arguments (1 given) How can I fix the problem ? Any pointer would be appreciated. Thanks in advance Nils
Nils Wagner a écrit :
Hi all,
I tried to use the home-made function (available at http://www.scipy.org/Cookbook/InputOutput) to read an array from the file topo-28.xohis (See attachment for details).
If I run the script (xy.py) I get
python -i xy.py Traceback (most recent call last): File "xy.py", line 47, in ? data = readArray("topo-28.xohis") File "xy.py", line 35, in readArray items = split(stripped_line) stripped_line.split() ?
help split gives this: split(ary, indices_or_sections, axis=0) Divide an array into a list of sub-arrays. Description: Divide ary into a list of sub-arrays along the specified axis. If indices_or_sections is an integer, ary is divided into that many equally sized arrays. If it is impossible to make an equal split, an error is raised. This is the only way this function differs from the array_split() function. If indices_or_sections is a list of sorted integers, its entries define the indexes where ary is split. On 10/26/07, Nils Wagner <nwagner@iam.uni-stuttgart.de> wrote:
Hi all,
I tried to use the home-made function (available at http://www.scipy.org/Cookbook/InputOutput) to read an array from the file topo-28.xohis (See attachment for details).
If I run the script (xy.py) I get
python -i xy.py Traceback (most recent call last): File "xy.py", line 47, in ? data = readArray("topo-28.xohis") File "xy.py", line 35, in readArray items = split(stripped_line) TypeError: split() takes at least 2 arguments (1 given)
How can I fix the problem ?
Any pointer would be appreciated.
Thanks in advance
Nils
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
On Sat, 27 Oct 2007 11:49:01 -0500 "Ryan Krauss" <ryanlists@gmail.com> wrote:
help split gives this:
split(ary, indices_or_sections, axis=0) Divide an array into a list of sub-arrays.
Description: Divide ary into a list of sub-arrays along the specified axis. If indices_or_sections is an integer, ary is divided into that many equally sized arrays. If it is impossible to make an equal split, an error is raised. This is the only way this function differs from the array_split() function. If indices_or_sections is a list of sorted integers, its entries define the indexes where ary is split.
On 10/26/07, Nils Wagner <nwagner@iam.uni-stuttgart.de> wrote:
Hi all,
I tried to use the home-made function (available at http://www.scipy.org/Cookbook/InputOutput) to read an array from the file topo-28.xohis (See attachment for details).
If I run the script (xy.py) I get
python -i xy.py Traceback (most recent call last): File "xy.py", line 47, in ? data = readArray("topo-28.xohis") File "xy.py", line 35, in readArray items = split(stripped_line) TypeError: split() takes at least 2 arguments (1 given)
How can I fix the problem ?
Any pointer would be appreciated.
Thanks in advance
Nils
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
There are two different split functions. Finally I have used from string import lstrip,split # Now python xy.py works for me :-). Cheers, Nils Help on function split in module string: split(s, sep=None, maxsplit=-1) split(s [,sep [,maxsplit]]) -> list of strings Return a list of the words in the string s, using sep as the delimiter string. If maxsplit is given, splits at no more than maxsplit places (resulting in at most maxsplit+1 words). If sep is not specified or is None, any whitespace string is a separator. (split and splitfields are synonymous)
Are you trying to do somthing like this: In [19]: myline = '1.0, 2.0, 3.0, 4.0' In [20]: mylist = myline.split(',') In [21]: mylist Out[21]: ['1.0', ' 2.0', ' 3.0', ' 4.0'] In [22]: mylist = [item.strip() for item in mylist] In [23]: mylist Out[23]: ['1.0', '2.0', '3.0', '4.0'] In [24]: myfloats = [float(item) for item in mylist] In [25]: myfloats Out[25]: [1.0, 2.0, 3.0, 4.0] On 10/26/07, Nils Wagner <nwagner@iam.uni-stuttgart.de> wrote:
Hi all,
I tried to use the home-made function (available at http://www.scipy.org/Cookbook/InputOutput) to read an array from the file topo-28.xohis (See attachment for details).
If I run the script (xy.py) I get
python -i xy.py Traceback (most recent call last): File "xy.py", line 47, in ? data = readArray("topo-28.xohis") File "xy.py", line 35, in readArray items = split(stripped_line) TypeError: split() takes at least 2 arguments (1 given)
How can I fix the problem ?
Any pointer would be appreciated.
Thanks in advance
Nils
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
participants (3)
-
fred
-
Nils Wagner
-
Ryan Krauss