473,387 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to read fields from a file?

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
3 1277
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Nik Coughin | last post by:
Is there a simple way of opening a text file from a server, and reading from it line by line? IE http://someserver/file.txt contains a couple of hundred lines. Each line is the name of a...
7
by: KantKwitDansin1 | last post by:
I have a file "a.dat" containing 10^4 32 bit binary numbers. I need to read in these numbers and deterimine if they are prime. The primality part I will have to figure out later, but I was...
6
by: G.Esmeijer | last post by:
Friends, I would like to read a text file (fixed length formaated) really fast and store the data into an Access database (2003). Using the streamreader and reading line by line, separating the...
10
by: Paulb1us | last post by:
I have a CSV file, like the one you can save in Excel. I want to use C# .NET to read the file and place the data into a sql2k data base. and then import another file that would update those same...
5
by: Just Me | last post by:
Using streams how do I write and then read a set of variables? For example, suppose I want to write into a text file: string1,string2,string3 Then read them later. Suppose I want to write...
8
by: james | last post by:
I am trying to use Filestream to read a file ( .DAT) that contains values in HEX that I want to convert to text. I know the different offset addresses for each portion of the data I am trying to...
4
by: Antonio Tirado | last post by:
Hi, I'm using the OleDB namespace to open a CSV File. I can read the file sucessfully except for hyphenated values. My CSV File contains phone numbers and sometimes these come separated with...
2
by: Patrik Birgersson | last post by:
Hi there! I've been trying for days to find a solution anywhere on the web to this problem and I hope you might be able to sort me out. I want to use PHP and COM to set and read values of MS...
0
by: Cas | last post by:
Hi, I defined a detailsview in insertmode in the .aspx file. In the code-behind, i created 6 fields and adding them to the detailsview. Independantly of the detailsview, I use the datareader to...
23
by: ShaneO | last post by:
Hello, I wish to extract embedded string data from a file using a Binary Read method. The following code sample is used in VB.NET and similar code is used in VB6 - (Assume variable...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.