Hello,
I would like to store multiple dictionaries in a file, if possible one per
line. My code currently produces a new dictionary every iteration and
passes it on to another peace of code. In order to be able to re-run some
experiments at a later date I would like to store every dictionary in the
same file.
I looked at pickel, but that seems to require a whole file for each
dictionary.
It would be great if some one could tell me how to do that.
Thank you,
Phil 7 2517
Philipp H. Mohr wrote: Hello,
I would like to store multiple dictionaries in a file, if possible one per line.
Why "one per line" ?
My code currently produces a new dictionary every iteration and passes it on to another peace of code.
May this code rest in piece <grin>
In order to be able to re-run some experiments at a later date I would like to store every dictionary in the same file. I looked at pickel, but that seems to require a whole file for each dictionary.
It would be great if some one could tell me how to do that.
A pretty simple solution could be to store all the dicts in another
container (list or dict, depending on how you need to retrieve'em, but
from what you explain I'd say a list) and then pickle this container.
My 2 cents...
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Thank you for you answer. I would like to store multiple dictionaries in a file, if possible one per line. Why "one per line" ?
I agree with you that it sounds like nasty code :-) but there is a good
reason for doing it this way - I think. My code collects data (attributes)
of its current environment, e.g. date, time, location, etc.
These values are put into a dictionary and passed to another program which
processes the data. The dictionary (or vector of attributes) is the only
interface between both progs. The one which creates the dictionary can
forget about it after it has passed it on. This is where the storing comes
into action. In order to be able to re-run an experiment I want to store
the dictionaries in a file. Also the program might not run continuasly,
therefore if I write all of them to a file, on after the other, I would be
able to re-run the experiment much easier.
Hope this makes sense.
Thank you,
Phil A pretty simple solution could be to store all the dicts in another container (list or dict, depending on how you need to retrieve'em, but from what you explain I'd say a list) and then pickle this container.
Philipp H. Mohr wrote: I would like to store multiple dictionaries in a file, if possible one per line. My code currently produces a new dictionary every iteration and passes it on to another peace of code. In order to be able to re-run some experiments at a later date I would like to store every dictionary in the same file. I looked at pickel, but that seems to require a whole file for each dictionary.
If you're not worried about security, you could write the repr() of each
dict to the file and get the values back by using the eval() function.
repr() writes onto one line.
If you're storing types without repr() representations this will not work.
Jeremy
--
Jeremy Sanders http://www.jeremysanders.net/
bruno modulix wrote: Philipp H. Mohr wrote: My code currently produces a new dictionary every iteration and passes it on to another peace of code.
May this code rest in piece <grin>
Perhaps it's the piece of code that passeth all understanding?
bruno modulix wrote: Philipp H. Mohr wrote: My code currently produces a new dictionary every iteration and passes it on to another peace of code.
May this code rest in piece <grin>
Perhaps it's the piece of code which passeth all understanding?
You might want to take a look at the shelve module.
-Larry
Philipp H. Mohr wrote: Hello,
I would like to store multiple dictionaries in a file, if possible one per line. My code currently produces a new dictionary every iteration and passes it on to another peace of code. In order to be able to re-run some experiments at a later date I would like to store every dictionary in the same file. I looked at pickel, but that seems to require a whole file for each dictionary.
It would be great if some one could tell me how to do that.
Thank you, Phil
Hello,
this is the solution I went for, as I am indeed not concernt about
security and the implementation is straight forward.
Thank you,
Phil If you're not worried about security, you could write the repr() of each dict to the file and get the values back by using the eval() function. repr() writes onto one line.
If you're storing types without repr() representations this will not work.
Jeremy This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Lars Behrens |
last post by:
Hi there!
For a web project I need a little expert help. I don't have written much
code yet, just been fiddling around a bit, testing and planning.
The web site will have a submission page for...
|
by: Bulba! |
last post by:
Hello everyone,
I'm reading the rows from a CSV file. csv.DictReader puts
those rows into dictionaries.
The actual files contain old and new translations of software
strings. The dictionary...
|
by: Livin |
last post by:
I'm a noobie so please be easy on me. I have searched a ton and did not find
anything I could understand.
I'm using py2.3
I've been using Try/Except but this gets long with multiple...
|
by: manstey |
last post by:
Hi,
I am running a script that produces about 450,000 dictionaries. I tried
putting them into a tuple and then pickling the tuple, but the tuple
gets too big. Can I pickle dictionaries one after...
|
by: IamIan |
last post by:
Hello,
I'm writing a simple FTP log parser that sums file sizes as it runs. I
have a yearTotals dictionary with year keys and the monthTotals
dictionary as its values. The monthTotals dictionary...
|
by: loial |
last post by:
I need to store a list of variable names in a dictionary or list. I
then later need to retrieve the names of the variables and get the
values from the named variables. The named variables will...
|
by: lysdexia |
last post by:
I'm having great fun playing with Markov chains. I am making a
dictionary of all the words in a given string, getting a count of how
many appearances word1 makes in the string, getting a list of...
|
by: shigehiro |
last post by:
Hi all,
Further to my 'list of dictionaries' question yesterday, I would to ask how to write data to csv file format using 'list of dictionaries' as a source:
data to be written to .csv file:...
|
by: M.-A. Lemburg |
last post by:
On 2008-08-07 20:41, Laszlo Nagy wrote:
1
It also very fast at dumping/loading lists, tuples, dictionaries,
floats, etc.
--
Marc-Andre Lemburg
eGenix.com
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |