[Tutor] Change a text string from a list and change it into an integer number.(WinXP/py2.6.2/Beginner)
Katt
the_only_katala at verizon.net
Fri Nov 6 03:44:06 CET 2009
Hello all,
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[0]
if check_year == "cyear":
year = localtime().tm_year
else:
year = int(date2[0])
print year
So my goal here is for python to check at the value of "date". If the value
of "date[0]" is cyear then I want it to get the current year from the
computer. If the value of date[0] 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
say:
"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
"c".
All input is appreciated.
Thanks in advance,
Katt
More information about the Tutor
mailing list