Beginners question

Ulrich Eckhardt ulrich.eckhardt at dominolaser.com
Thu Aug 30 10:41:19 EDT 2012


Am 30.08.2012 15:27, schrieb Marco Nawijn:
> On Thursday, August 30, 2012 3:15:03 PM UTC+2, Ulrich Eckhardt wrote:
>> Am 30.08.2012 13:54, schrieb boltar2003 at boltar.world:
>>> What sort of object is posix.stat_result?
[...]
>> I guess that this is a named tuple, which is a tuple where the
>> attributes are not indexed but have a name, see the
>> documentation for the namedtuple() function from the collections
>> library.
>>
>
> It is not a namedtuple. Because a namedtuple "is" a tuple and therefore isinstance(s, tuple) would have returned True.
>
>>>> from collections import namedtuple
>>>> Point = namedtuple('Point', 'x y')
>>>> p = Point(10,2)
>>>> isinstance(p, tuple)
> True

Hi Marco,

I don't find anything wrong with what you say, the output formatting 
from using a type created by namedtuple would have been slightly 
different indeed. However, I also don't understand the point you're 
trying to make, in particular why it matters that a namedtuple type is 
derived from tuple, other than perhaps that access by name is available 
in addition to access by index.

Greetings!

Uli




More information about the Python-list mailing list