Module runs in stash but not on console
I am trying to understand the use of modules in stash and on the python console. I have a module that runs perfectly in stash with a command like:
Module_name -s d blabla
"-s d blabla" are necessary arguments in this example . I cannot figure out how to do the same thing from the Pythonista console. I can import the module, but any way I try to add the arguments, I get the error:
SyntaxError: invalid syntax
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 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.
@djl and this in the console?
@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.
@djl Ok, sorry, I didn't understand correctly your post, my fault 😢
The equivalent in the python console is
sys.argv=[arg0, arg1, ...]
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
Take a look at the module's if name=='main' section-- sometimes they call out to a main() method that you could replicate.
Thank you Jon. That worked when I entered the argv statement followed by:
I'm just learning how all of this fits together.
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)