omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Module runs in stash but not on console

    Pythonista
    console stash
    4
    11
    6179
    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.
    • bennr01
      bennr01 last edited by

      @djl said:

      "-s d blabla" are necessary arguments in this example . I cannot figure out how to do the same thing from the Pythonista console.

      You can long-press the run-Button to add arguments

      Regarding the SyntaxError: Maybe you run StaSh in a different python version than the console?

      djl 1 Reply Last reply Reply Quote 0
      • djl
        djl @bennr01 last edited by

        @bennr01

        I tried long press to run arguments in a script, and it didn't work. I don't see such an option when using the console command line. I checked python versions and also paths in the console and in stash -- they are the same.

        cvp 1 Reply Last reply Reply Quote 0
        • cvp
          cvp @djl last edited by

          @djl

          djl 1 Reply Last reply Reply Quote 0
          • djl
            djl @cvp last edited by

            @cvp thank you for your help, but my original question dealt with the python console command line, not from within a script. If one runs the module itself using the long_press method, it starts the init script and added arguments do nothing. I am just trying to replicate what happens so easily in stash, in the normal Pythonista framework, and I'm not getting anywhere.

            cvp 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @djl last edited by

              @djl and this in the console?

              import webbrowser;webbrowser.open('pythonista://script_name?action=run&argv=p1&argv=p2')
              
              djl 1 Reply Last reply Reply Quote 0
              • djl
                djl @cvp last edited by

                @cvp there is no script with the functionality of the module invoked in the stash command line. The is a module with sub modules, including init

                Without understanding the answer to my original question, I did discover a workaround. If I import a submodule from the main module, I can reproduce expected output by directly calling some of the included functions. I am just surprised that this is so different than simply invoking the main module in stash.

                cvp 1 Reply Last reply Reply Quote 0
                • cvp
                  cvp @djl last edited by

                  @djl Ok, sorry, I didn't understand correctly your post, my fault 😢

                  1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB last edited by

                    The equivalent in the python console is
                    import run_py
                    sys.argv=[arg0, arg1, ...]
                    runpy.run_module(module and)

                    Where arg0 is the script name.

                    Alternatively, import module would also work the first time, if you have set sys.argv. but subsequent imports don't run __main__.

                    Take a look at the module's if name=='main' section-- sometimes they call out to a main() method that you could replicate.

                    djl 1 Reply Last reply Reply Quote 0
                    • djl
                      djl @JonB last edited by

                      @JonB
                      Thank you Jon. That worked when I entered the argv statement followed by:

                      Package_name.module_name.main()
                      

                      I'm just learning how all of this fits together.

                      1 Reply Last reply Reply Quote 0
                      • JonB
                        JonB last edited by

                        no problem. for modules that define a main like that, that will work. in some cases, a module might have

                        if __name__=='__main__':
                            do_stuff()
                        

                        in which case, run_py is the way to go (python -m actually uses run_py under the hood)

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Powered by NodeBB Forums | Contributors