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

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to