Τη Παρασκευή, 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.
>
> >
>
Τη Παρασκευή, 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
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[
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
Τη Παρασκευή, 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
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
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
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
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
Τη Παρασκευή, 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
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,
> 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
Τη Παρασκευή, 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:
>
>
Τη Παρασκευή, 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:
>
>
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")
Τη Παρασκευή, 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
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,
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
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
> έγραψε:
>
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
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
Τη Παρασκευή, 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
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
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
Τη Πέμπτη, 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' )
>
>
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
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
27 matches
Mail list logo