Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialleonardo valdes
12,384 Pointsprogram works on pycharm but not on terminal?
I used the same code that kenneth wrote in the video, and it runs fine after installing pytz on pycharm. When I run it on the terminal, however, i get a syntax error when I input local_date. I dont know why it works on one but not the other?
from datetime import datetime
import pytz
OTHER_TIMEZONES = [pytz.timezone('US/Eastern'),
pytz.timezone('Pacific/Auckland'),
pytz.timezone('Asia/Calcutta'),
pytz.timezone('UTC'),
pytz.timezone('Europe/Paris'),
pytz.timezone('Africa/Khartoum')
]
fmt = '%Y-%m-%d %H:%M:%S %Z%z'
while True:
date_input = input('When is your meeting? Use MM/DD/YYYY HH:MM format.: ')
try:
local_date = datetime.strptime(date_input, '%m/%d/%Y %H:%M')
except ValueError:
print("{} doesn't seem to be a valid date and time...".format(date_input))
else:
local_date = pytz.timezone('US/Pacific').localize(local_date)
utc_date = local_date.astimezone(pytz.utc)
output = []
for timezone in OTHER_TIMEZONES:
output.append(utc_date.astimezone(timezone))
for appointment in output:
print(appointment.strftime(fmt))
break
1 Answer
Steven Parker
231,236 PointsIt looks like lines 19 and 21 (after the "except" and the "else") should be indented.
leonardo valdes
12,384 Pointssorry, they actually were indented. I edited the question to avoid confusion.
Steven Parker
231,236 PointsIf I add the indentation it runs without error.
leonardo valdes
12,384 Pointsthats weird because i definitely indented when i wrote it, and it runs without error on pycharm. the only time I've gotten the syntax error is if i try to run it directly from the terminal.
Steven Parker
231,236 PointsPerhaps I'm misunderstanding what you mean by "directly from the terminal". I'm running it from the console in the workspace. Do you mean something else?
leonardo valdes
12,384 Pointsleonardo valdes
12,384 Pointswhen I run it on the terminal as just python meetings.py i get the syntax error, but when i use python3 meetings.py it works without error. Should we use python3 instead of python?