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 a module or script from command line. python -m module_name
-
I had struggled with using modules that were meant to be invoked using the command line such as unittest and pylint. I recently discovered that you could call python SimpleHTTPServer to share files with others on the network. However, I could not figure out how to use python in Pythonista's interpreter.
I made a little script that will run a python module or script with args. It simulates the console command:
>python -m module|script [args]It sets the directory to the currently opened editor file. It's useful for running standard library modules and .py files with args.
-
@briarfox Thanks, that looks neat. I didn't know runpy, I must learn it. I'd been using execfile() and/or silent notifications.
-
@tony I just stumbled upon it. runpy contains two functions and it's easy to use :) Its nice to be able to finally run modules via command line. Would have saved me a lot of banging my head against a wall earlier on. Makes TDD much easier.
-
@briarfox. It's a great utility, I like it. I was hoping even that runpy might avoid the threading issues, but it seems not. This little test script has the same problems as if execfile or silent notifications were used. Its the current version of Pythonista though I think, not you.
import console # test which thread are we in... console alert not good in main ui thread console.alert('Test', button1 = 'OK', hide_cancel_button = True)