Python program won't run correctly when opened from folder or desktop, but works fine when run in IDLE
up vote
0
down vote
favorite
I have created a simple task-timing program in which the user presses a key to start a timer, and again to stop. The program displays the time elapsed. This all works fine when i run the program, however after this I have the time and task name saved to a file. When run in IDLE (and NetBeans), this save works perfectly. However in the command window, the program closes, not before briefly displaying a traceback error. The data is not saved to the file (which is in the same folder as my program).
Here is the code:
*import time
task = input('What task are you completing?n')
print('Press ENTER to begin. Afterwards, press ENTER to "click" the stopwatch. Press Ctrl-C to quit.')
input()
print('Started.')
startTime = time.time()
lastTime = startTime
while True:
input()
totalTime = round(time.time() - startTime, 2)
totalTime = str(totalTime)
seconds = int(float(totalTime))
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
periods = [('hours', hours), ('minutes', minutes), ('seconds', seconds)]
time_string = ', '.join('{} {}'.format(value, name)
for name, value in periods
if value)
print(str(task) + ' took: ' + time_string)
time.sleep(2)
print('Saving to file')
time.sleep(3)
writefile = open('Timelog.csv','a')
writefile.write(task + ', ' + time_string + '')
writefile.close()
break
end = input('Press enter to close')
Any help is greatly appreciated.
python stopwatch traceback
add a comment |
up vote
0
down vote
favorite
I have created a simple task-timing program in which the user presses a key to start a timer, and again to stop. The program displays the time elapsed. This all works fine when i run the program, however after this I have the time and task name saved to a file. When run in IDLE (and NetBeans), this save works perfectly. However in the command window, the program closes, not before briefly displaying a traceback error. The data is not saved to the file (which is in the same folder as my program).
Here is the code:
*import time
task = input('What task are you completing?n')
print('Press ENTER to begin. Afterwards, press ENTER to "click" the stopwatch. Press Ctrl-C to quit.')
input()
print('Started.')
startTime = time.time()
lastTime = startTime
while True:
input()
totalTime = round(time.time() - startTime, 2)
totalTime = str(totalTime)
seconds = int(float(totalTime))
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
periods = [('hours', hours), ('minutes', minutes), ('seconds', seconds)]
time_string = ', '.join('{} {}'.format(value, name)
for name, value in periods
if value)
print(str(task) + ' took: ' + time_string)
time.sleep(2)
print('Saving to file')
time.sleep(3)
writefile = open('Timelog.csv','a')
writefile.write(task + ', ' + time_string + '')
writefile.close()
break
end = input('Press enter to close')
Any help is greatly appreciated.
python stopwatch traceback
hmm works fine for me using the command line, how are you executing the file and what does the traceback say?
– smoggers
Nov 10 at 20:05
double-clicking from the folder it is in, unsure as to what the traceback says, only way I can think to check is to record my screen and slow it down. Out of interest, does the data save to a file? (Assuming you created a file with the same name of course) Thanks
– Matt Oram
Nov 10 at 20:16
yes it saves the data to the csv file
– smoggers
Nov 10 at 20:21
Please post the traceback error too. (I guess that when you are executing your program from within the terminal, you don't have the permission to write your csv file - in contrast to when it runs from the IDE - but that is only a guess)
– quant
Nov 10 at 21:31
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have created a simple task-timing program in which the user presses a key to start a timer, and again to stop. The program displays the time elapsed. This all works fine when i run the program, however after this I have the time and task name saved to a file. When run in IDLE (and NetBeans), this save works perfectly. However in the command window, the program closes, not before briefly displaying a traceback error. The data is not saved to the file (which is in the same folder as my program).
Here is the code:
*import time
task = input('What task are you completing?n')
print('Press ENTER to begin. Afterwards, press ENTER to "click" the stopwatch. Press Ctrl-C to quit.')
input()
print('Started.')
startTime = time.time()
lastTime = startTime
while True:
input()
totalTime = round(time.time() - startTime, 2)
totalTime = str(totalTime)
seconds = int(float(totalTime))
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
periods = [('hours', hours), ('minutes', minutes), ('seconds', seconds)]
time_string = ', '.join('{} {}'.format(value, name)
for name, value in periods
if value)
print(str(task) + ' took: ' + time_string)
time.sleep(2)
print('Saving to file')
time.sleep(3)
writefile = open('Timelog.csv','a')
writefile.write(task + ', ' + time_string + '')
writefile.close()
break
end = input('Press enter to close')
Any help is greatly appreciated.
python stopwatch traceback
I have created a simple task-timing program in which the user presses a key to start a timer, and again to stop. The program displays the time elapsed. This all works fine when i run the program, however after this I have the time and task name saved to a file. When run in IDLE (and NetBeans), this save works perfectly. However in the command window, the program closes, not before briefly displaying a traceback error. The data is not saved to the file (which is in the same folder as my program).
Here is the code:
*import time
task = input('What task are you completing?n')
print('Press ENTER to begin. Afterwards, press ENTER to "click" the stopwatch. Press Ctrl-C to quit.')
input()
print('Started.')
startTime = time.time()
lastTime = startTime
while True:
input()
totalTime = round(time.time() - startTime, 2)
totalTime = str(totalTime)
seconds = int(float(totalTime))
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
periods = [('hours', hours), ('minutes', minutes), ('seconds', seconds)]
time_string = ', '.join('{} {}'.format(value, name)
for name, value in periods
if value)
print(str(task) + ' took: ' + time_string)
time.sleep(2)
print('Saving to file')
time.sleep(3)
writefile = open('Timelog.csv','a')
writefile.write(task + ', ' + time_string + '')
writefile.close()
break
end = input('Press enter to close')
Any help is greatly appreciated.
python stopwatch traceback
python stopwatch traceback
asked Nov 10 at 19:57
Matt Oram
43
43
hmm works fine for me using the command line, how are you executing the file and what does the traceback say?
– smoggers
Nov 10 at 20:05
double-clicking from the folder it is in, unsure as to what the traceback says, only way I can think to check is to record my screen and slow it down. Out of interest, does the data save to a file? (Assuming you created a file with the same name of course) Thanks
– Matt Oram
Nov 10 at 20:16
yes it saves the data to the csv file
– smoggers
Nov 10 at 20:21
Please post the traceback error too. (I guess that when you are executing your program from within the terminal, you don't have the permission to write your csv file - in contrast to when it runs from the IDE - but that is only a guess)
– quant
Nov 10 at 21:31
add a comment |
hmm works fine for me using the command line, how are you executing the file and what does the traceback say?
– smoggers
Nov 10 at 20:05
double-clicking from the folder it is in, unsure as to what the traceback says, only way I can think to check is to record my screen and slow it down. Out of interest, does the data save to a file? (Assuming you created a file with the same name of course) Thanks
– Matt Oram
Nov 10 at 20:16
yes it saves the data to the csv file
– smoggers
Nov 10 at 20:21
Please post the traceback error too. (I guess that when you are executing your program from within the terminal, you don't have the permission to write your csv file - in contrast to when it runs from the IDE - but that is only a guess)
– quant
Nov 10 at 21:31
hmm works fine for me using the command line, how are you executing the file and what does the traceback say?
– smoggers
Nov 10 at 20:05
hmm works fine for me using the command line, how are you executing the file and what does the traceback say?
– smoggers
Nov 10 at 20:05
double-clicking from the folder it is in, unsure as to what the traceback says, only way I can think to check is to record my screen and slow it down. Out of interest, does the data save to a file? (Assuming you created a file with the same name of course) Thanks
– Matt Oram
Nov 10 at 20:16
double-clicking from the folder it is in, unsure as to what the traceback says, only way I can think to check is to record my screen and slow it down. Out of interest, does the data save to a file? (Assuming you created a file with the same name of course) Thanks
– Matt Oram
Nov 10 at 20:16
yes it saves the data to the csv file
– smoggers
Nov 10 at 20:21
yes it saves the data to the csv file
– smoggers
Nov 10 at 20:21
Please post the traceback error too. (I guess that when you are executing your program from within the terminal, you don't have the permission to write your csv file - in contrast to when it runs from the IDE - but that is only a guess)
– quant
Nov 10 at 21:31
Please post the traceback error too. (I guess that when you are executing your program from within the terminal, you don't have the permission to write your csv file - in contrast to when it runs from the IDE - but that is only a guess)
– quant
Nov 10 at 21:31
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Is there any chance that you can open a command-prompt/terminal-session and execute from there? That would let you grab the trace.
I'm guessing quant has the right of it and you're running into a access/permissions hurdle of some kind. You can also try saving to a filename that doesn't exist yet; maybe it's just overwriting the file created with the IDE that's is the problem.
Hi Pete, thanks for this suggestion. I ran it from cmd and lo and behold, no error - the code runs perfectly. Guess that's the way it is - very little a reboot won't solve haha.
– Matt Oram
Nov 11 at 14:24
Glad it helped Matt!
– Pete Reitz
Nov 13 at 13:09
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Is there any chance that you can open a command-prompt/terminal-session and execute from there? That would let you grab the trace.
I'm guessing quant has the right of it and you're running into a access/permissions hurdle of some kind. You can also try saving to a filename that doesn't exist yet; maybe it's just overwriting the file created with the IDE that's is the problem.
Hi Pete, thanks for this suggestion. I ran it from cmd and lo and behold, no error - the code runs perfectly. Guess that's the way it is - very little a reboot won't solve haha.
– Matt Oram
Nov 11 at 14:24
Glad it helped Matt!
– Pete Reitz
Nov 13 at 13:09
add a comment |
up vote
0
down vote
accepted
Is there any chance that you can open a command-prompt/terminal-session and execute from there? That would let you grab the trace.
I'm guessing quant has the right of it and you're running into a access/permissions hurdle of some kind. You can also try saving to a filename that doesn't exist yet; maybe it's just overwriting the file created with the IDE that's is the problem.
Hi Pete, thanks for this suggestion. I ran it from cmd and lo and behold, no error - the code runs perfectly. Guess that's the way it is - very little a reboot won't solve haha.
– Matt Oram
Nov 11 at 14:24
Glad it helped Matt!
– Pete Reitz
Nov 13 at 13:09
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Is there any chance that you can open a command-prompt/terminal-session and execute from there? That would let you grab the trace.
I'm guessing quant has the right of it and you're running into a access/permissions hurdle of some kind. You can also try saving to a filename that doesn't exist yet; maybe it's just overwriting the file created with the IDE that's is the problem.
Is there any chance that you can open a command-prompt/terminal-session and execute from there? That would let you grab the trace.
I'm guessing quant has the right of it and you're running into a access/permissions hurdle of some kind. You can also try saving to a filename that doesn't exist yet; maybe it's just overwriting the file created with the IDE that's is the problem.
answered Nov 10 at 22:06
Pete Reitz
413
413
Hi Pete, thanks for this suggestion. I ran it from cmd and lo and behold, no error - the code runs perfectly. Guess that's the way it is - very little a reboot won't solve haha.
– Matt Oram
Nov 11 at 14:24
Glad it helped Matt!
– Pete Reitz
Nov 13 at 13:09
add a comment |
Hi Pete, thanks for this suggestion. I ran it from cmd and lo and behold, no error - the code runs perfectly. Guess that's the way it is - very little a reboot won't solve haha.
– Matt Oram
Nov 11 at 14:24
Glad it helped Matt!
– Pete Reitz
Nov 13 at 13:09
Hi Pete, thanks for this suggestion. I ran it from cmd and lo and behold, no error - the code runs perfectly. Guess that's the way it is - very little a reboot won't solve haha.
– Matt Oram
Nov 11 at 14:24
Hi Pete, thanks for this suggestion. I ran it from cmd and lo and behold, no error - the code runs perfectly. Guess that's the way it is - very little a reboot won't solve haha.
– Matt Oram
Nov 11 at 14:24
Glad it helped Matt!
– Pete Reitz
Nov 13 at 13:09
Glad it helped Matt!
– Pete Reitz
Nov 13 at 13:09
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242872%2fpython-program-wont-run-correctly-when-opened-from-folder-or-desktop-but-works%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
hmm works fine for me using the command line, how are you executing the file and what does the traceback say?
– smoggers
Nov 10 at 20:05
double-clicking from the folder it is in, unsure as to what the traceback says, only way I can think to check is to record my screen and slow it down. Out of interest, does the data save to a file? (Assuming you created a file with the same name of course) Thanks
– Matt Oram
Nov 10 at 20:16
yes it saves the data to the csv file
– smoggers
Nov 10 at 20:21
Please post the traceback error too. (I guess that when you are executing your program from within the terminal, you don't have the permission to write your csv file - in contrast to when it runs from the IDE - but that is only a guess)
– quant
Nov 10 at 21:31