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.


    run script from console / commandline

    Pythonista
    3
    9
    9515
    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.
    • robopu
      robopu last edited by

      simple question. i wrote a script in editorial console and it works fine there. pasted it to pythonista and it runs when i hit the play button.

      but i want to execute it from the cmdline so i can redirect output to a file.

      i'm trying :

      python script.py

      but there is no love. script.py lives in the root directory of the pythonista library.. it appears the console is trying to interpret script.py as a sting.. sorry if it's simple question but a dumb answer but the documentation told me the above is what i'm supposed to be running.. i can't give the file perms and i'm not sure i need to include an interpreter comment line up at the top of the file as if i was in linux...

      thanks

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

        well if i just type 'python'.. it thinks that's a string too ;).. so is the documentation wrong? it looks like i'm obviously already in the interpretter and it wants python language statements issued here individually

        fwiw, i would like to write print output from script to a file using redirection. it's easier if i can run the script form the cmdline vs having to code it up

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

          Pythonista does not provide a bash console. The console is a Python interpreter. You can try reading sys.stdout and writing its contents to a file.

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

            sidenote: quick question with my script. in editorial it didn't mind if the print statements weren't wrapped in ().. but pythonista is demanding it meaning i have to go and change all my print statements. would prefer not to have to do that.. there are lots of them.. is there a way to just disable this somehow in this script?.. i'll be sure to use () in going forward ;)

            1 Reply Last reply Reply Quote 0
            • robopu
              robopu @Webmaster4o last edited by

              @Webmaster4o

              ok.. but i could swear the documentation just showed me an example of running a script using:

              python script.py

              since this is pythonista documentation.. i figured they meant it when they said it ;) even if i can't use redirect per bash, can i still invoke a script per above (though i guess it doesn't give me much advantage other than that i don't have to load the actual script in the editor to run it)?

              thx

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

                It's a difference between Python 2 and Python 3. Editorial is still on Python 2. While Pythonista supports both, 3 is the newer version and the default.

                If you'd like to use Python 2 as the default for compatibility with Editorial, check out the "default interpreter" option on the settings.

                1 Reply Last reply Reply Quote 0
                • Webmaster4o
                  Webmaster4o @robopu last edited by

                  @robopu You're probably reading the official documentation from the Python Software Foundation, which targets desktop computers over Pythonista. Everything about the Python language will be the same, but the other stuff may be a little different. So no, you can't invoke a Python script like that.

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

                    ok thx for both those replies webmaster.. makes sense..

                    1 Reply Last reply Reply Quote 1
                    • ywangd
                      ywangd last edited by ywangd

                      This is the use case that StaSh was initially created for. You can invoke your script from within StaSh similar to what you would do on a PC. You can redirect the output to a file as the follows:

                      your_script.py > output.txt
                      

                      More details here https://github.com/ywangd/stash
                      If you have previous experience with Linux shell, things should be quite familiar.

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