Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
[SOLVED] Help with int() error (short code)
-
Ok, so I'm making something that counts down the number of days to an event.
Here's the code to the one that works (without user input):
<pre><code>
import datetime
today = datetime.date.today()
someday = datetime.date(2015,8,24)
diff = someday - today
print(diff.days)
</code></pre>Here's the one that doesn't work (with user input):
<pre><code>
import datetime
import console
today = datetime.date.today()
find = console.input_alert('Date', 'Please enter the date you would like to countdown to.\ni.e. 2009 (year),6 (month),29 (day)', '', 'Enter')
someday = datetime.date(find)
diff = someday - today
print(diff.days)
</code></pre>Thanks in advance!
-
console.input_alert
returns a string, but you need three numbers. You could convert it like this:# ... try: year, month, day = [int(s.strip()) for s in find.split(',')] someday = datetime.date(year, month, day) diff = someday - today print(diff.days) except ValueError: print 'Incorrect date format (must be "year, month, day")'
-
Thanks a lot @omz!