[Tutor] Through a glass, darkly: the datetime module
Dave Angel
d at davea.name
Sun Oct 7 03:42:01 CEST 2012
On 10/06/2012 09:10 PM, Richard D. Moores wrote:
> On Sat, Oct 6, 2012 at 4:29 PM, Dave Angel <d at davea.name> wrote:
>
>> To turn an integer (0-6, or whatever) into a string, just use a tuple of
>> the same size:
>>
>> tran = ("MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY",
>> "SATURDAY", "SUNDAY")
>> i = 1
>> print tran[i]
>>
>> (prints "TUESDAY")
>
> Why did you choose "tran"?
>
> Dick
>
>
tran was short for "translation table." It's also the name of a keyword
I implemented in an interpreter over 35 years ago.
Of course, Mark has pointed out that equivalent functionality is already
in the calendar module
i = 1
print calendar.day_name[i]
day_name isn't a list or tuple, but it behaves enough like one for this
purpose.
--
DaveA
More information about the Tutor
mailing list