Structure accessible by attribute name or index
Wes Santee
wsantee at gmail.com
Wed Mar 17 12:40:44 EDT 2010
On Mar 17, 11:14 am, Christian Heimes <li... at cheimes.de> 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:http://docs.python.org/library/collections.html#namedtuple-factory-fu...
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