Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Ferrous Cranus
Τη Παρασκευή, 22 Φεβρουαρίου 2013 7:38:47 μ.μ. UTC+2, ο χρήστης Ferrous Cranus έγραψε: > Τη Παρασκευή, 22 Φεβρουαρίου 2013 5:25:41 μ.μ. UTC+2, ο χρήστης Lele Gaifax > έγραψε: > > > Ferrous Cranus writes: > > > > > > > > > > > > > but the try: solution is much more less hassle. > > > >

Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Ferrous Cranus
Τη Παρασκευή, 22 Φεβρουαρίου 2013 5:25:41 μ.μ. UTC+2, ο χρήστης Lele Gaifax έγραψε: > Ferrous Cranus writes: > > > > > but the try: solution is much more less hassle. > > > > ... not to mention it is more effective than your simplicistic check :-) > > > > ciao, lele. > > -- > > nickna

Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Tim Chase
On 2013-02-22 07:07, Ferrous Cranus wrote: > Actually it can, but instead of try: i have to create a function: > > def is_sane_date(date): > parts = [int(part) for part in date.split() if part.isdigit()] > if len(parts) == 3 and \ > 1 <= parts[0] <= 31 and \ > 1 <= parts[

Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Lele Gaifax
Ferrous Cranus writes: > but the try: solution is much more less hassle. ... not to mention it is more effective than your simplicistic check :-) ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l

Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Ferrous Cranus
Τη Παρασκευή, 22 Φεβρουαρίου 2013 3:35:31 μ.μ. UTC+2, ο χρήστης Lele Gaifax έγραψε: > Ferrous Cranus writes: > > > > > Let me ask it like this: > > > How can i avoid using try: except: for checkign the date but instead check > > it with an if statement: > > > > Let me answer this way: you

Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Andreas Perstinger
Lele Gaifax wrote: >Ferrous Cranus writes: > >> Let me ask it like this: >> How can i avoid using try: except: for checkign the date but instead >> check it with an if statement: > >Let me answer this way: you can't, without resorting to the simple >helper functions I wrote in my previous message

Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Chris Angelico
On Sat, Feb 23, 2013 at 12:35 AM, Lele Gaifax wrote: > Ferrous Cranus writes: > >> Let me ask it like this: >> How can i avoid using try: except: for checkign the date but instead check >> it with an if statement: > > Let me answer this way: you can't, without resorting to the simple > helper fu

Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Lele Gaifax
Ferrous Cranus writes: > Let me ask it like this: > How can i avoid using try: except: for checkign the date but instead check it > with an if statement: Let me answer this way: you can't, without resorting to the simple helper functions I wrote in my previous message. Why do you dislike that

Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Ferrous Cranus
i made a liitle typo at the ned, i meant this: if ( eval( datetime.strptime(date, '%d %m %Y') ) ): date = datetime.strptime(date, '%d %m %Y').strftime('%Y-%m-%d') else: print( "Date wasn't entered properly" ) -- http://mail.python.org/mailman/listinfo/python-list

Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Ferrous Cranus
Τη Παρασκευή, 22 Φεβρουαρίου 2013 2:03:39 μ.μ. UTC+2, ο χρήστης Lele Gaifax έγραψε: > Ferrous Cranus writes: > > > > > I'am thinking if somehting like the follwoing work: > > > > > > if( task and ( price and price.isdigit() and price.__len__() <= 3 ) and ( > > date and eval( datetime.strpti

Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Lele Gaifax
Ferrous Cranus writes: > I'am thinking if somehting like the follwoing work: > > if( task and ( price and price.isdigit() and price.__len__() <= 3 ) and ( > date and eval( datetime.strptime(date, '%d %m %Y').strftime('%Y-%m-%d') ) ) ): a) you should not (usually) call “dunder methods” directly,

Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Ferrous Cranus
> I'am thinking if somehting like the follwoing work: > > if( task and ( price and price.isdigit() and price.__len__() <= 3 ) and ( > date and eval( datetime.strptime(date, '%d %m %Y').strftime('%Y-%m-%d') ) ) ): I just tried it out this workaround so to avoid having an extra try: except: but

Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Ferrous Cranus
Τη Παρασκευή, 22 Φεβρουαρίου 2013 8:20:20 π.μ. UTC+2, ο χρήστης rob.mar...@gmail.com έγραψε: > The datetime function: strptime() DOES check the date for validity. So try > something like: > > > > from datetime import datetime > > > > def get_date(): > > while True: > > try: > >

Re: Checking for valid date input and convert appropriately

2013-02-22 Thread Ferrous Cranus
Τη Παρασκευή, 22 Φεβρουαρίου 2013 8:20:20 π.μ. UTC+2, ο χρήστης rob.mar...@gmail.com έγραψε: > The datetime function: strptime() DOES check the date for validity. So try > something like: > > > > from datetime import datetime > > > > def get_date(): > > while True: > > try: > >

Re: Checking for valid date input and convert appropriately

2013-02-21 Thread rob . marshall17
The datetime function: strptime() DOES check the date for validity. So try something like: from datetime import datetime def get_date(): while True: try: date_in = raw_input("Enter date (dd mm ): ") date_out = datetime.strptime(date_in,"%d %m %Y").strftime("%Y-%m-%d")

Re: Checking for valid date input and convert appropriately

2013-02-21 Thread Ferrous Cranus
Τη Παρασκευή, 22 Φεβρουαρίου 2013 2:57:03 π.μ. UTC+2, ο χρήστης Michael Ross έγραψε: > On Fri, 22 Feb 2013 01:12:40 +0100, Ferrous Cranus > wrote: > > Please i have been trying hours for this: > Don't do that: Spending hours on being stuck. Take a break. Call it a > > night. > > Brain nee

Re: Checking for valid date input and convert appropriately

2013-02-21 Thread Michael Ross
On Fri, 22 Feb 2013 01:12:40 +0100, Ferrous Cranus wrote: Please i have been trying hours for this: Don't do that: Spending hours on being stuck. Take a break. Call it a night. Brain needs time to unstick itself. Besides: from datetime import date entry='31 03 2013' day, month,

Re: Checking for valid date input and convert appropriately

2013-02-21 Thread Ferrous Cranus
Please i have been trying hours for this: try: datetime.strptime(date, '%d m% %Y') date = date.strftime('%Y-%m-%d') except: print( "date not propetly entered." ) sys.exit(0) === the user enters

Re: Checking for valid date input and convert appropriately

2013-02-21 Thread Michael Ross
On Fri, 22 Feb 2013 00:08:01 +0100, Ferrous Cranus wrote: Τη Παρασκευή, 22 Φεβρουαρίου 2013 12:03:59 π.μ. UTC+2, ο χρήστης Michael Ross έγραψε: On Thu, 21 Feb 2013 22:22:15 +0100, Ferrous Cranus wrote: > Τη Πέμπτη, 21 Φεβρουαρίου 2013 10:14:13 μ.μ. UTC+2, ο χρήστης MRAB > έγραψε: >

Re: Checking for valid date input and convert appropriately

2013-02-21 Thread Mark Lawrence
On 21/02/2013 23:18, Ferrous Cranus wrote: Then i try to save the date as MySQL wants but it just aint happening: date = datetime.strftime(date, '%Y-%m-%d') Can you help me please save the user entered date to MySQL format? I suggest testing your code at the interactive prompt, so something

Re: Checking for valid date input and convert appropriately

2013-02-21 Thread Ferrous Cranus
Then i try to save the date as MySQL wants but it just aint happening: date = datetime.strftime(date, '%Y-%m-%d') Can you help me please save the user entered date to MySQL format? -- http://mail.python.org/mailman/listinfo/python-list

Re: Checking for valid date input and convert appropriately

2013-02-21 Thread Ferrous Cranus
Τη Παρασκευή, 22 Φεβρουαρίου 2013 12:03:59 π.μ. UTC+2, ο χρήστης Michael Ross έγραψε: > On Thu, 21 Feb 2013 22:22:15 +0100, Ferrous Cranus > > wrote: > > > > > Τη Πέμπτη, 21 Φεβρουαρίου 2013 10:14:13 μ.μ. UTC+2, ο χρήστης MRAB > > > έγραψε: > > >> On 2013-02-21 19:38, Ferrous Cranus wro

Re: Checking for valid date input and convert appropriately

2013-02-21 Thread Michael Ross
On Thu, 21 Feb 2013 22:22:15 +0100, Ferrous Cranus wrote: Τη Πέμπτη, 21 Φεβρουαρίου 2013 10:14:13 μ.μ. UTC+2, ο χρήστης MRAB έγραψε: On 2013-02-21 19:38, Ferrous Cranus wrote: > import datetime from datetime Should be: from datetime import datetime > > try: > datetime.strpt

Re: Checking for valid date input and convert appropriately

2013-02-21 Thread MRAB
On 2013-02-21 21:22, Ferrous Cranus wrote: Τη Πέμπτη, 21 Φεβρουαρίου 2013 10:14:13 μ.μ. UTC+2, ο χρήστης MRAB έγραψε: On 2013-02-21 19:38, Ferrous Cranus wrote: > import datetime from datetime Should be: from datetime import datetime > > try: > datetime.strptime( date, '%d %m %Y' ) That

Re: Checking for valid date input and convert appropriately

2013-02-21 Thread Ferrous Cranus
Τη Πέμπτη, 21 Φεβρουαρίου 2013 10:14:13 μ.μ. UTC+2, ο χρήστης MRAB έγραψε: > On 2013-02-21 19:38, Ferrous Cranus wrote: > > > import datetime from datetime > > > > Should be: > > > > from datetime import datetime > > > > > > > > try: > > > datetime.strptime( date, '%d %m %Y' ) > >

Re: Checking for valid date input and convert appropriately

2013-02-21 Thread MRAB
On 2013-02-21 19:38, Ferrous Cranus wrote: import datetime from datetime Should be: from datetime import datetime try: datetime.strptime( date, '%d %m %Y' ) That parses the date and discards the result. date = date.strptime( '%Y-%m-%d' ) 'date' is a string, it doesn't have a

Checking for valid date input and convert appropriately

2013-02-21 Thread Ferrous Cranus
import datetime from datetime try: datetime.strptime( date, '%d %m %Y' ) date = date.strptime( '%Y-%m-%d' ) except ValueError: print( "H ημερομηνία πρέπει να εισαχθεί στην σωστή μορφή => 21 05 2013!" ) sys.exit(0) Hello, a have an html that among