Re: Returning a tuple-struct
- From: Tim Roberts <timr@xxxxxxxxx>
- Date: Sun, 22 Jan 2006 06:52:01 GMT
groups.20.thebriguy@xxxxxxxxxxxxxxx wrote:
>I've noticed that there's a few functions that return what appears to
>be a tuple, but that also has attributes for each item in the tuple.
>For example, time.localtime() returns a time.time_struct, which looks
>like a tuple but also like a struct. That is, I can do:
>
>>>> time.localtime()
>(2006, 1, 18, 21, 15, 11, 2, 18, 0)
>>>> time.localtime()[3]
>21
>>>> time.localtime().tm_hour
>21
Ah, but it ISN'T really a tuple:
>>> import time
>>> t = time.localtime()
>>> type(t)
<type 'time.struct_time'>
>>> str(t)
'(2006, 1, 21, 22, 49, 32, 5, 21, 0)'
It's a class object. The __repr__ method returns a string that LOOKS the
same as a tuple.
--
- Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.
.
- References:
- Returning a tuple-struct
- From: groups . 20 . thebriguy
- Returning a tuple-struct
- Prev by Date: Some thougts on cartesian products
- Next by Date: Help needed with Weave and XP and MSVC 6.0
- Previous by thread: Re: Returning a tuple-struct
- Next by thread: web crawling.
- Index(es):
Relevant Pages
|