Reputation: 3
I've made a simple Script that tells you the Time. It works fine in Shell but when I try to run the File the Console opens and closes immediatly.
Here's the scipt :
from datetime import datetime
now = datetime.now()
print "Hello I am Robot that tells you the time!"
print "Do you want to know what time it is?"
A = raw_input("Yes (Y) / No (N)")
if A == "Y" or "y":
print "It is %s:%s !" % (now.hour, now.minute)
elif A == "N" or "n":
print "Okay maybe next time!"
else:
print "What do you mean by that?"
raw_input("press Enter to end")
Upvotes: 0
Views: 66
Reputation: 3
I am so sorry for bothering you with this Question. As it turns out in the Programm there was an error that Shell tolareted but the Terminal didn't. I wrote
if A == "y" or "Y"
instead of
if A == "y" or A == "Y"
Upvotes: 0
Reputation: 319
In case you're having an exception and exiting before coming to raw_input()
line, try this, it'll show your exception:
if __name__ == '__main__':
try:
## do your stuff here
except:
import sys
print sys.exc_info()[0]
import traceback
print traceback.format_exc()
print "Press Enter to continue ..."
raw_input()
if you want to keep the window open no matter the case, add this to above code:
finally:
print "Press Enter to continue ..."
raw_input()
Upvotes: 1
Reputation: 868
What I do in situations like this (with no errors) is this: put a print() with a unique input after each line of code. you'll get to know which part causes the problem. It's not professional I guess, but it works for small code.
Upvotes: 1