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

2009-11-05 Thread Shashwat Anand
import time def katt(d): date0 = d.split("_")[0] if date0 == "cyear": return int(time.strftime("%Y")) else: return int(date0) print katt("cyear_11_05") print katt("1984_11_05") l0nwlf-Arena:l0nwlf$ python katt.py 2009 1984 http://codepad.org/RBjKmNcA Hope this help

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

2009-11-05 Thread Shashwat Anand
What do you want to say exactly ? is 'cyear' an integer ? let's say date1 = "1984_11_05" Then of course you can change it to an integer using following list-comprehension, >>> date1 = "1984_11_05" >>> date1_list = [int(i) for i in date1.split("_")] >>> date1_list [1984, 11, 5] or alternatively, >>

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

2009-11-05 Thread Wayne Werner
On Thu, Nov 5, 2009 at 8:44 PM, Katt wrote: > > 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 stea

Re: [Tutor] parameters vs arguments

2009-11-05 Thread BINTO
I understand now… Thanks Binto From: ALAN GAULD [mailto:alan.ga...@btinternet.com] Sent: Friday, November 06, 2009 7:41 AM To: BINTO Subject: Re: [Tutor] parameters vs arguments > Parameter is what used to give/call value in function. > Argument is what used to give/call value in c

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

2009-11-05 Thread Katt
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_ye

Re: [Tutor] Retrieving information from a plain text file(WinXP/py2.6.2/Beginner)

2009-11-05 Thread Katt
Hello all, Thank you all for your help. I appreciate it alot. I have been trying to work with file IO alot recently and would like to improve my little program so that I no longer use a hard coded list, but a text file that I can edit easily. The text file is three lines long and looks exa

Re: [Tutor] Evaluating a string expression

2009-11-05 Thread Modulok
[snip] > I would like to know how would I evaluate a string expression in python. > For example, if i say: a = "3*2" > I want to do something to evaluate the variable 'a' to give me 6. How > can I do this? [/snip] The eval() function can do this: eval("3*2") WARNING: Long winded security

Re: [Tutor] parameters vs arguments

2009-11-05 Thread BINTO
Parameter is what used to give/call value in function. Argument is what used to give/call value in command line interface. Am I correct??... Binto -Original Message- From: tutor-bounces+binto=triplegate.net...@python.org [mailto:tutor-bounces+binto=triplegate.net...@python.org] On Behalf

Re: [Tutor] Stolen thread: Bottom folk vs. toppers was trouble using2to3.py

2009-11-05 Thread OkaMthembo
I'm afraid you guys are witty! Good on you. Rob, you're right - and Alan, you're right too. BRA-VO. On Wed, Nov 4, 2009 at 12:19 AM, Alan Gauld wrote: > "Robert Berman" wrote > > The war between bottom posters and top posters has been long, arduous, >> and most often incredibly silly. >> > > It