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
Re: [Tutor] Use iterator to refer to an object's attribute?
by Kent Johnson other posts by this author
Apr 20 2006 4:45AM messages near this date
[Tutor] Use iterator to refer to an object's attribute? | Re: [Tutor] Use iterator to refer to an object's attribute?
Ron Britton wrote:
>  Short version:  How do I use an iterator to refer to an object's  
>  attribute?  E.g., "z" is a list of attributes of  "b":
>  for x, y in z:
>       for a in b.x.y

getattr(b, 'foo') is the same as b.foo. getattr takes a string for the
name of the attribute. So you would need
    getattr(getattr(b, x), y)
>  
>  Also, any suggestions for my overall structure below?

For once I agree with Alan on a design question :-)

You can define a useful structure directly in your configuration. It
could be nested lists and dictionaries or nested class instances,
whichever works better for the application. I think I would use nested
class instances. This is one of Python's great strengths - that you can
easily declare complex data structures in code.

PS I suggest you call your data structure something other than 
'database' since that word has a fairly specific meaning.

Kent


_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Ron Britton
Kent Johnson
Ron Britton
Alan Gauld
Alan Gauld

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved