Community
    • Login

    Python Script help, stop execution

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 839 Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          skimmer333
          last edited by

          Thanks heaps. Makes sense to me now.

          1 Reply Last reply Reply Quote 1

          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
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors