Can anyone tell me why this code runs differently in python console than IDLE?
print('Do not press enter before the program says go.\n', end = '')
try:
while True:
input('Ready?')
print('Starting', end = '')
for i in range(secrets.randbits(3)):
time.sleep(1)
print(' .', end = '')
now = datetime.datetime.now()
input('\nGo!')
print('\nReaction: {}'.format(datetime.datetime.now()-now))
except KeyboardInterrupt:
print('Exiting.')
This is the output in IDLE which works the way I expect:
Do not press enter before the program says go.
Ready?
Starting . .
Go!
Reaction: 0:00:00.328174
But when in the console I get the same overall output but the dots do not show up one after the other, instead they all appear at once with go.Can anyone explain this strange behaviour. I am running Python 3.6.2 if that helps.
I do have a way to test if the program is running from IDLE or not which returns true if in idle and false if not in idle:
def inIDLE():
import sys
if 'idlelib.run' in sys.modules:
return True
else:
return False