I need to write 2 member lists to a file. For each record the number
of these lists can be different. I think a good way to handle that may
be to make each record a list of lists. I am restricted to using
version 2.2. That being the case what is a good standard record
separator to use to ensure that I read in one record (list of lists)
at a time, '\n'? I want to try to stay with what is considered
standard python idioms.
Thanks,
jvh 6 1595
HMS Surprise wrote:
I need to write 2 member lists to a file. For each record the number
of these lists can be different. I think a good way to handle that may
be to make each record a list of lists. I am restricted to using
version 2.2. That being the case what is a good standard record
separator to use to ensure that I read in one record (list of lists)
at a time, '\n'? I want to try to stay with what is considered
standard python idioms.
Thanks,
jvh
You really haven't given us quite enough info, but here goes:
If I control this file I might just write out a list of lists
on each line and eval it (not tested):
[['a', 'b'], ['c','d']]
[['a', 'b'], ['c','d'], ['e','f']]
fp=open(filename, 'r')
lists=[]
for n, line in enumerate(fp):
try: l=eval(line)
except SyntaxError:
print "SyntaxError on line=%i" % (n+1)
lists.append(l)
If you want something different, I might use a tab between lists
and commas between values.
-Larry
On 2007-05-15, HMS Surprise <jo**@datavoiceint.comwrote:
I need to write 2 member lists to a file. For each record the number
of these lists can be different. I think a good way to handle that may
be to make each record a list of lists. I am restricted to using
version 2.2. That being the case what is a good standard record
separator to use to ensure that I read in one record (list of lists)
at a time, '\n'? I want to try to stay with what is considered
standard python idioms.
Your description is a bit vague, but if I'm guessing your task
correctly, the standard idiom is to use the pickle module: http://www.python.org/doc/2.2.3/lib/module-pickle.html
You can use it to write pretty much any python object to a file.
--
Grant Edwards grante Yow! Nipples, dimples,
at knuckles, NICKLES,
visi.com wrinkles, pimples!!
Thanks folks. Was unaware of enumerate , still have a lot to learn
about python.
Sorry for the poorly phrased request, but you gathered the gist of it.
My wonderment is how to write the following 2 lines and make sure they
are saved as separate records or lines so that I pull in only one at a
time with readline(?).
['a', 'b'], ['c','d']]
[['a', 'b'], ['c','d'], ['e','f']]
Would like to use pickle but it is apparently unavailable in the
package I am using, Jython 2.2.
On 2007-05-15, HMS Surprise <jo**@datavoiceint.comwrote:
Would like to use pickle but it is apparently unavailable in the
package I am using, Jython 2.2.
Odd. At least in 2.4, pickle.py seems to be Jython-aware.
--
Grant Edwards grante Yow! does your DRESSING
at ROOM have enough ASPARAGUS?
visi.com
HMS Surprise wrote:
Thanks folks. Was unaware of enumerate , still have a lot to learn
about python.
Sorry for the poorly phrased request, but you gathered the gist of it.
My wonderment is how to write the following 2 lines and make sure they
are saved as separate records or lines so that I pull in only one at a
time with readline(?).
['a', 'b'], ['c','d']]
[['a', 'b'], ['c','d'], ['e','f']]
Would like to use pickle but it is apparently unavailable in the
package I am using, Jython 2.2.
I am pretty sure some version of pickle or cPickle is available in Jython 2.1,
though. I'd take a second look, to be sure.
>
Would like to use pickle but it is apparently unavailable in the
package I am using, Jython 2.2.
I am pretty sure some version of pickle or cPickle is available in Jython 2.1,
though. I'd take a second look, to be sure.
Many thanks Boris!
import cPickle
caused no errors! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave Stone |
last post by:
Does anyone know if it's possible to use the wizard or DTS Designer to
accept a source file with the following simplified format:
<field1label>: <record1field1value>
<field2label>: ...
|
by: Brian |
last post by:
Hello,
I have a text file I'm attempting to parse. There are about 50 fixed width
fields in each line / row. For example (shortened for brevity):
W1234Somebody East 101110001111010101...
|
by: sparks |
last post by:
I have never done this and wanted to ask people who have what is the
best way.
One person said import it to excel, then import it into access table.
but since this will be done a lot, I am...
|
by: happy |
last post by:
/* Book name : The prodessional programmers guide to C
File name : E:\programs\tc\iti01\ch09\main\01setupm.c
Program discription: file setuping -up -Version 01-ver01-W
Logic ...
|
by: M |
last post by:
Hi,
I need to parse text files to extract data records. The files will
consist of a header,
zero or more data records, and a trailer. I can discard the header and
trailer but I must split the...
|
by: nickm687 |
last post by:
Hi i have this code below and i need to modify it so i can pass more
than one text file to it. any ideas? i am new to this. thanks in
advance.
Nick
int main(int argc, char *argv) {
FILE *f;...
|
by: Julia |
last post by:
Hi, there,
I am trying to append a binary file by using:
FILE *strean;
stream = fopen( "c:\temp.dat", "ba+" ));
Is there a way that I can check if the file exists or not before
fopen,...
|
by: kanthi84 |
last post by:
Hiiiiiiiiiiii
In my project, i need to set separators in the text file. this text file is stored in the database as blob. The separators should help to retrieve the headings from the textfile...
|
by: maylee21 |
last post by:
hi, anyone can help me figure out how to read data from a text file
like this:
10980012907200228082002
and extract the data according to this kind of format:
Record type 1
TY-RECORD ...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |