473,326 Members | 2,655 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,326 software developers and data experts.

best way to do this ...

Hi ALL,

I am having a issue with a particular storage of data problem and
wanted to know if I am going about it the wrong way.

I have a list of reference numbers associated with a product and I have
a socket that listens on a port. Now what happens is the client app
connects to the server - sends the product and the associated ref
numbers (there are a few per product). I need to be able to store these
in a data structure so that when the same product is called again -
it can display the ref numbers for that product.

I am new to OO programming - so please have mercy ;)

eg:
class ProductData:
def __init__(self,prod):
self.prod = prod
self.ref = []
def add_ref(self,refno):
self.ref.append(refno)
def __str__(self):
return "%s : %s" % (self.prod,",".join(self.ref))
products = ['table', 'chair', 'couch']
ref_numbers = ['1234','4567', '7890']

detail = {}
id = 0

for p in products:
detail[id] = ProductData(p)
for r in ref_numbers:
detail[id].add_ref(r)
id = id + 1

for a in detail:
print detail[a]
so I will get:

table : 1234,4567,7890
chair : 1234,4567,7890
couch : 1234,4567,7890

BUT I will need to be able to have this in a while loop - as there is a
socket listener there.

I keep getting this error:

for a in Detail:
RuntimeError: dictionary changed size during iteration
any ideas ?

Thanks
Tonino

what I want to be able to get is a dict of the products and associated

Jul 19 '05 #1
2 1149
Am Tue, 17 May 2005 05:26:15 -0700 schrieb Tonino:
Hi ALL,

I am having a issue with a particular storage of data problem and
wanted to know if I am going about it the wrong way.

I have a list of reference numbers associated with a product and I have
a socket that listens on a port. Now what happens is the client app
connects to the server - sends the product and the associated ref
numbers (there are a few per product). I need to be able to store these
in a data structure so that when the same product is called again -
it can display the ref numbers for that product.
The smallest database is the filesystem. Create a directory for every
product. Store the references in a file in this directory.

for a in Detail:
RuntimeError: dictionary changed size during iteration


I did not see any dict in your code, but this message means, that you
can't change the dictionary in the loop. Maybe this helps:

for a, b in list(mydict.items()):
....
Thomas

--
Thomas Güttler, http://www.thomas-guettler.de/
Jul 19 '05 #2
hmm - but I want to store the data in memory eather than a filesystem
.... it is not an issue if the program terminates - it is almost needed
while running and does not need to remember where it is ..

the dirctionary is detail = {}

will try the list() function - thanks

Tonino

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Gemini | last post by:
Hello I am looking for the best content/article manager software, perferred open source, php, mysql backend.. can anyone recommend me one? I think that the best discussion is phpbb, the...
18
by: Roman Suzi | last post by:
;-) Just type into google "best programming language" and press (I am lucky) Sincerely yours, Roman Suzi -- rnd@onego.ru =\= My AI powered by GNU/Linux RedHat 7.3
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
3
by: Irene | last post by:
Hi all, I have set up a simple VB program (and later on an ASP interface) to manage an Athletics database. I'm using Access 2000. To simplify, I have the Athlets, the Competitions and the...
5
by: l.woods | last post by:
I want your recommendation on which ASP.NET Shopping Cart software I should buy? Best code Best documentation Best support (if needed. I will buying source code, if possible) TIA, Larry...
4
by: Ron Brennan | last post by:
Good evening, Windows 2000, JDK 1.5. What opinions do people have on what way and tool programmaticly produces the best quality thumbnails from larger images? On the web I've seen Java...
7
by: Frank Millman | last post by:
Hi all Assume a 2-dimensional list called 'table' - conceptually think of it as rows and columns. Assume I want to create a temporary copy of a row called 'row', allowing me to modify the...
9
by: optimistx | last post by:
Which url in your opinion would be a good or even the best example of javascript usage in a set of pages at least say 10 or more pages? How to use css, how to split js-code to files, how to code...
24
by: Earl | last post by:
I have all of my data operations in a separate library, so I'm looking for what might be termed "best practices" on a return type from those classes. For example, let's say I send an update from...
9
by: =?Utf-8?B?QW1tZXI=?= | last post by:
I've read many incomplete opinions about the "Best Practice" for securely accessing SQL but what I really need to find the "Best Practice" that fits my applications needs. Currently (alpha...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
0
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...
1
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)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.