470,810 Members | 873 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

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 1115
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Gemini | last post: by
18 posts views Thread by Roman Suzi | last post: by
136 posts views Thread by Matt Kruse | last post: by
5 posts views Thread by l.woods | last post: by
4 posts views Thread by Ron Brennan | last post: by
7 posts views Thread by Frank Millman | last post: by
9 posts views Thread by optimistx | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.