ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
[Tutor] Prevent "Coder's Remorse"?
by Ron Phillips other posts by this author
Sep 28 2005 4:45AM messages near this date
Re: [Tutor] Reformatting a one (long) line xml file | Re: [Tutor] Prevent "Coder's Remorse"?
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
_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Ron Phillips
Danny Yoo
Poor Yorick
Ron Phillips
Kent Johnson
Ron Phillips
Kent Johnson
Kent Johnson
Alan G

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved