Help with Dictionaries and Classes requested please.

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Aug 9 09:57:33 EDT 2007


special_dragonfly a écrit :
> "Bruno Desthuilliers" <bruno.42.desthuilliers at wtf.websiteburo.oops.com> 
> wrote in message news:46baf183$0$433$426a74cc at news.free.fr...
>> special_dragonfly a écrit :
>> (snip)
(and resnip)

> Hello
> To answer first Bjoern:
> I have a dictionary and a class. The dictionary needs to be filled with 
> multiple instances of the class, with multiple instances per key. Currently 
> a lot of the dictionaries that are going into the program are hard coded 
> because they're just 1:1 mappings, in this case though it was a many:1 
> mapping and so I got a little stumped. I couldn't hard coded the mappings, 
> so I then needed to find a way of doing it dynamically. I'm now reading data 
> from a file containing the data for the class, and am now able to put that 
> data into a dictionary.
> 
> I'm quite new to programming large things, and previous experience has only 
> been in C and C++, so I'm also trying to get an idea of good programming 
> practises.

FWIW, and while there of course are quite a few common rules (consistent 
and meaningfull naming, modularization with high cohesion and low 
coupling, "don't repeat yourself" etc), "good programming practises" 
greatly vary from language to language. In fact, one of the common rules 
is probably : "be idiomatic" - that is, don't try to write Pascal in 
Lisp (or C in Python...).

> Other people are going to need to use this program, I need it to 
> be... correct... should someone need to alter it. So loads of documentation, 
> and meaningful variable names, but it's also experience that I'm lacking.

Indeed.

> Is 
> there a better way of doing such-and-such, or is it sensible to do it this 
> way....?

I second Steven's suggestion to spend some time going thru introductory 
material. IMHO, the official Python tutorial (to get the basics - no pun 
intended) and then DiveIntoPython (to see the language in action) should 
do.

Then you'll find that most people here will be very happy to help you 
rewrite your code in the most pythonic way if you kindly ask for help...

> Thank you for your help, all of you.

Welcome to c.l.py.



More information about the Python-list mailing list