Why does the custom shortcut append the editor file path ?
if you run the following as a custom shortcut
import sys, editor, console console.clear() print('\nwhy does the custom shortcut append the editor file path ?') print(sys.argv) print('\nwhen you can get the path from the editor library') print(editor.get_path()) print('\nwhich is a more intuitive way to do it')
@eddo888 I'm sorry but I have to insist.
If you start a script from an (home screen) shortcut, you can't be sure that the script is in an edited tab. In this case, editor.get_path will not return the path of your script but the path of the edited script......which could be different of the wanted path.
@cvp sys.argv is allways the actual script
@eddo888 Sure. I only explain why you never have to use editor.get_path
sys.argv.pop() # does not seem too ugly
try: # from pythonista libraries import editor # fix for pythonista tools icons if sys.argv[-1] == editor.get_path(): argv = sys.argv[1:-1] else: argv = sys.argv[1:] except: argv = sys.argv[1:]
@cvp Thanks for responding, it is encouraging that a thriving Pythonista community exists.
my desire is to have a Rossum approach to code so my scripts work on all my platforms
import editor # fix for pythonista tools icons if sys.argv[-1] == editor.get_path(): sys.argv.pop() argv = sys.argv[1:]
@ccc at the risk of going on about it,
if shortcusts didn't put a redunant arg on the args list
I wouldn't have to do anything.
The main use case for wrench shortcuts was for processing scripts in the editor.
thus, for scripts which take one arg, a filename, sys.argv is being populated the way you would run from the command line --  is the command name,  is the target file. Anyway, that's the rationale behind the first two args -- the idea was to be able to have a script that accepts a file name, and does something to that file -- publishing to a blog, converting markdown to html, etc -- and you could run that script on your desktop or on pythonista in the same way.
Running from the play button or from a home screen shortcut probably shouldn't populate argv unless you asked it to.
Arguably, it would be nice to have a switch in the wrench editor, that says whether it populates argv with the editor filename, or not.
If you want to simulate a pure command line that doesn't pass in the editor filename, you should consider writing a little launcher script, that populates sys.argv, and then calls runpy that way you can run your other scripts. I.e have a single launcher script that accepts as argv the module to run and any argv -- then simply fix argv and call runpy.
elegent response, thanks for taking the time to provide a thorough detailed description. I'm glad I have an opportunity to try and contribute to such a wonderful app such is Pythonista. one of my favourite in flight/bus/walking/lunch/etc entertainment apps.