Structure accessible by attribute name or index

Wes Santee wsantee at
Wed Mar 17 17:40:44 CET 2010

On Mar 17, 11:14 am, Christian Heimes <li... at> wrote:
> Wes Santee wrote:
> > I am very new to Python, and trying to figure out how to create an
> > object that has values that are accessible either by attribute name,
> > or by index.  For example, the way os.stat() returns a stat_result or
> > pwd.getpwnam() returns a struct_passwd.
> > In trying to figure it out, I've only come across C implementations of
> > the above types.  Nothing specifically in Python.  What is the Python
> > native way to create this kind of object?
> > I apologize if this has been widely covered already.  In searching for
> > an answer, I must be missing some fundamental concept that is
> > excluding me from finding an answer.
> You can't use the same implementation as the result object of os.stat()
> and others. However Python 2.6 has a new factory that creates a similar
> datatype called named tuple:

Thanks for the pointer.  At least I know there is a reason why I
wasn't finding a solution. :)

More information about the Python-list mailing list