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.










share|improve this question






















  • 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















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.










share|improve this question






















  • 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













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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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












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.






share|improve this answer





















  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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.






share|improve this answer





















  • 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















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.






share|improve this answer





















  • 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













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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."