Read a record instead of a line from a file

Maan M. Hamze mmhamze at pleiades.net
Fri Aug 24 10:22:54 EDT 2001


If there is a record separator then you can safely treat it as a database.
if you are on Windows, create an ODBC datasource and use the ODBC library
that comes with PythonWin.  If you are not using Pythonwin, use something
like mxODBC to access records using the ODBC datasource.  Basically, you
have what resembles a CSV file.  If you are on Unix, use an ODBC datasource
bridge.  Check the mxODBC site for more information.
Now, if you do not want to deal with datasources at all - what I can think
of (I have not tried this since  I use ODBC datasources on windows) is to
open the file, then look for what separates the different values/columns
WITHIN one record, then add these values into a list:
The list itself is a collection of lists indexed by the number of the
record.  Each new index is created when the record separator is encountered.
For each index, a list is created to keep track of the values inside each
record.
I think you see the point now.
Of course, there maybe some other way of which I am not aware of since I
only use ODBC.  But I can see a list of lists (a list of records - each
record is created when the record separator is encountered - and each record
is a list of values as different values are encountered within each record).
Maan

"YMK" <gbeymk at sgh.com.sg> wrote in message
news:3B86028A.9F5F9967 at sgh.com.sg...
> If I know the "Record Separator" of a flat file, how do I set to read
> one record at a time ?





More information about the Python-list mailing list