[Tutor] Change a text string from a list and change it into an integer number.(WinXP/py2.6.2/Beginner)
the_only_katala at verizon.net
Fri Nov 6 03:44:06 CET 2009
I was wondering if it was possible to split a string that is seperated by
the "_" character and changing the text into an integer?
My current code is as follows:
date = "cyear_11_05"
date2 = date.split("_")
check_year = date2
if check_year == "cyear":
year = localtime().tm_year
year = int(date2)
So my goal here is for python to check at the value of "date". If the value
of "date" is cyear then I want it to get the current year from the
computer. If the value of date is a number then I want to just change it
into an integer.
Currently the above code does not work unless I change the "if" statement to
"if check_year == "c".
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
All input is appreciated.
Thanks in advance,
More information about the Tutor