By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,965 Members | 1,702 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,965 IT Pros & Developers. It's quick & easy.

How to read fields from a file?

P: n/a
Hi,

I have a file with data written in a "matrix" form. In other words,
every row contains a fixed number of fields and I am interested in the
value of each field of every row.

I managed to read rows in the following way:
f = open('filename.dat','r')
for line in f:
x = line
f.close()

However, I cannot find out how to split every line into fields? What
should I do if I, let's say, need a value which is located in the
third row in the second column (field).

Thank you!
Sep 30 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I found line.split()! It works great! I think it is exactly what I
need. Or may be there are some more elegant solutions?
Oct 1 '08 #2

P: n/a
On Oct 1, 2:58*am, Kurda Yon <kurda...@yahoo.comwrote:
I found line.split()! It works great! I think it is exactly what I
need. Or may be there are some more elegant solutions
Why are you posting in comp.lang.php questions about language with is
not connected to PHP ?

LOL
Oct 1 '08 #3

P: n/a
On Oct 1, 5:07 am, Kristaps KŻlis <Kristaps.Ku...@gmail.comwrote:
On Oct 1, 2:58 am, Kurda Yon <kurda...@yahoo.comwrote:
I found line.split()! It works great! I think it is exactly what I
need. Or may be there are some more elegant solutions

Why are you posting in comp.lang.php questions about language with is
not connected to PHP ?

LOL
Sorry, I did it by a mistake. It should be python... Thank you that
you indicated that.
Oct 1 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.