Python Script help, stop execution
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.