[Tutor] Prevent "Coder's Remorse"?

Ron Phillips RPhillips at engineer.co.summit.oh.us
Wed Sep 28 13:44:15 CEST 2005


Maybe it's just me. I am always haunted by "coder's remorse" (the
certainty that there's a more compact, beautiful, fun, maintainable way
to code anything I finish.)
 
At any rate, I am currently working on a script to model an ordered
collection of geographic points, all of which must share the same
collection of attributes. So, a little collection might be:
 
pointList = [
{lat:40.123,lon:-81.456, 
    'attributes':{'msg':'example','beavers':34, 'distance':18.132}
},
{lat:40.12345,lon:-81.45678, 
    'attributes':{'msg':'','beavers':0, 'distance':0.0}
}
]
 
If I add an attribute of 'newAtt':'newVal' to
pointList[1]['attributes'], I want it to automatically add
'newAtt':'default' to
all the other member's 'attributes' dictionary. If I delete an
attribute, it should delete from all the member's dictionaries. The
attributes are limited to string, integer, and float values.
 
I can do this by brute force, but:

Is there an elegant approach that occurs to anyone? 
Is there a data structure that forces all members to have the same
keys? 
Is there an object structure that will let updates to one instance
affect all instances?
Am I even asking the right questions?

I suspect there's an elegant solution, but it's beyond me right now. If
not, fine; I'll happily go on with my ham-fisted approach.

Regards,




 
 

Ron Phillips
Programmer/Analyst
County of Summit Engineer
538 E. South St.
Akron, OH 44311


More information about the Tutor mailing list