Python Script help, stop execution
-
Hi all,
I’ve just started learning python and programming.
I have written up a simple script which prompts for three separate bits of info, and then uses that to create a folder and saves the document/tab to that folder.
So far it works ok. What I am now trying to achieve, is to stop the script if the Cancel button is selected on a prompt dialog box.
My code is as follows. I’m testing just using the first prompt, hence the console.write. I just can’t figure out what I need to do. (Note, I don’t want to close Npp, just stop the script from continuing. Any assistance would be greatly appreciated.from Npp import editor, notepad import os vPath = 'H:\\INCs' vNum = notepad.prompt('INC : ','Enter INC#','') if vNum == None: console.write('None') vFI = notepad.prompt('FI: ','Enter FI','') vDesc = notepad.prompt('Desc: ','Enter Description','') vBuild = str(vPath) + '\\' + str(vNum) + '-' + str(vFI) + ' ' + str(vDesc) vBuildAll = vBuild + '\\' + str(vNum) + '.txt' if not os.path.exists(vBuild): os.makedirs(vBuild) notepad.saveAs(vBuildAll); -
You make a function and return from it.
def main(directory): vNum = notepad.prompt('INC : ', 'Enter INC#', '') if vNum is None: console.write('None') return main(r'H:\INCs') -
Thanks heaps. Makes sense to me now.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login