ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
Re: [Tutor] Change a text string from a list and change it into an integer number.(WinXP/py2.6.2/Beginner)
by Katt other posts by this author
Nov 5 2009 6:53PM messages near this date
Re: [Tutor] can time.time() be reversed so as to get date? | Re: [Tutor] Change a text string from a list and change it into an integer number.(WinXP/py2.6.2/Beginner)
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@[...].org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Thread:
Katt
Shashwat Anand
Alan Gauld
Dave Angel
Shashwat Anand
Wayne Werner

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved