Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Python Script help, stop execution

    Help wanted · · · – – – · · ·
    2
    3
    162
    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.
    • skimmer333
      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);
      
      Ekopalypse 1 Reply Last reply Reply Quote 0
      • Ekopalypse
        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
        • skimmer333
          skimmer333 last edited by

          Thanks heaps. Makes sense to me now.

          1 Reply Last reply Reply Quote 1
          • First post
            Last post
          Copyright © 2014 NodeBB Forums | Contributors