[Tutor] Change a text string from a list and change it into an integer number.(WinXP/py2.6.2/Beginner)

Alan Gauld alan.gauld at btinternet.com
Fri Nov 6 09:44:51 CET 2009

"Katt" <the_only_katala at verizon.net> wrote

> date = "cyear_11_05"
> date2 = date.split("_")
> check_year = date2[0]
> if check_year == "cyear":
>    year = localtime().tm_year
> else:
>    year = int(date2[0])
> print year
> Did I do the slice incorrectly?  I thought that when you take the first 
> location (0) of a list then it would take the "cyear" in stead of just 
> the "c".

When debugging this kind of thing insert some print statements
to check what date2 and check_year really look like. Or try using
the >>> prompt to experiment until you are happy with the behaviour
of the function with differernt sample data.


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list