Community
    • Login

    Python Script help, stop execution

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 540 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • skimmer333S
      skimmer333
      last edited by

      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);
      
      EkopalypseE 1 Reply Last reply Reply Quote 0
      • EkopalypseE
        Ekopalypse @skimmer333
        last edited by

        @skimmer333

        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')
        
        1 Reply Last reply Reply Quote 3
        • skimmer333S
          skimmer333
          last edited by

          Thanks heaps. Makes sense to me now.

          1 Reply Last reply Reply Quote 1
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors