Python; jump to a concrete line
Tobiah
toby at tobiah.org
Thu Dec 20 17:08:03 EST 2007
Horacius ReX wrote:
> Hi, sorry but after looking for information, I still did not get how,
> when reading a text file in python, can one jump to a concrete line
> and then read the different data (separated by spaces). In each line
> there is different number of columns so sometimes i get kind of "index
> out" error. Is there a better way to read the different data on each
> row and avoiding to know the exact number of columns ?
>
> Thanks
There may be a language barrier here (probably on my side), but
I think that the OP was asking for something more elementary.
You have:
DATA DATA
DATA DATA DATA DATA
DATA DATA DATA
DATA DATA
DATA DATA
DATA DATA DATA
DATA DATA
DATA DATA
Read the file and 'jump' to line four, and then do:
line.split()[3]
and get "kind of 'index out' error"
So he could at least do:
l = line.split()
if len(l) > index:
data = l[index]
else:
data = None
Assuming index counts from zero.
Or perhaps I miss the point entirely.
--
Posted via a free Usenet account from http://www.teranews.com
More information about the Python-list
mailing list