[Tutor] changing string to integer in a script
alan.gauld at blueyonder.co.uk
Thu Jun 24 03:36:36 EDT 2004
> >>> import time
> >>> time.strftime('%H')
> >>> type (time.strftime('%H'))
> <type 'str'>
> So it looks like I am getting a string back instead of an integer.
> just assign it a number and run type on it again it looks OK...
the clue is in the name. strftime returns a *str*ing.
You might want to try using localtime() instead, that returns a tuple
of values, the 4th of which is the hour:
>>> hour = time.localtime()
> I'm sure I have not looked hard enough, but I can't see any way to
> change a string to an int.
int() works pretty well:
> I *imagine* it would be something kinda like:
Nope, just int() :-)
Author of the Learn to Program web tutor
More information about the Tutor