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 2559
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 attendants of a congress.
In a form the user will submit name, mailadress etc. and I plan to store
the data in a list of dictionaries:
People =
|
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 containing the row data looks like this:
o={'TermID':'4', 'English':'System Administration',
'Polish':'Zarzadzanie systemem'}
|
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 dictionaries.
I found some code on web pages and such but cannot get them to work. Any
help is appreciated as I need to search multiple dictionaries for keys.
|
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 another into the same
file and then read them out again?
Cheers,
Matthew
|
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 has month keys
and file size values. The script works except the results are written
for all years, rather than just one year. I'm thinking there's an
error in the way I set my dictionaries up or reference them...
import glob, traceback
| |
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 already have
been created and given a value.
I hope thats clear!!!
How can I do this?
|
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 all the
word2s that follow each appearance of word1 and a count of how many
times word2 appears in the string as well. (I know I should probably
be only counting how many times word2 actually follows word1, but as I
said, I'm having great fun...
|
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:
dictList =
so the csv file would look something like:
Michael,Kirk,224567
Linda,Matthew,123456
|
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: 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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |