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.
how to work efficient with multiple files?
-
Hi
I'm doing some code refactoring with pythonista. It works great, except the file switching is an efficient killer.
I often work with two files in different file trees. So I need to always walk up and down the directory structure only to take a quick look to another file.Is there a way to do a fast switch between two files?
Something like a file bookmark? Or any other workaround?
Multiple tabs would be great for a future version of pythonista!yves
-
Not really, you can emulate this with the Action menu though.
First, create a script that looks like this (call it "Switch to File" or something like that):
import sys import editor if len(sys.argv) > 1: editor.open_file(sys.argv[1])
Then, add it to the Action menu and set both the title of the action, and its arguments to the file you'd like to open (e.g. "Folder/MyScript.py"). Invoking the action should now open that file.
You can create multiple versions of the action with different arguments to access more than one file from the action menu.
-
Thanks for that suggestion, this brought me also to another idea. But I couldn't get that working.
The idea is to use symlinks. On the top level I make a directory "current".
I add the actions "add to current" and "remove from current".
The action "add to current" should symlink the current open file to the current folder.
So I could have symlinks to all current files I want to work with in a flat folder. So I can easy and fast switch to the files I want.The problem I'm facing is that I can't add symlinks with python. When I try "os.symlink" I get the error "'module' object has no attribute 'symlink'". I also tried "os.system("/bin/ln -s %s %s"), this returns 32512 (command not found).
Shouldn't be "/bin" world readable like mentioned on apple developer sandbox.
I only have rudimentary iOS programming knowledge, so I don't know if other security stuff is kicking in.Is there a way to make symlink in pythonista?
some ideas, only dreaming here :-):
A feature request for pythonista could be to display the last 5 open accessed files on the 5 bottom rows in the pythonista file browser.
Another would be to add a bookmark feature where the Delete... Move.. Action for files is. You could switch to the Bookmark view with left swipe when the file browser is open. -
@yvess, nice idea! I'd really like to have something like this.
-
I got a basic version working. See this gist. After I found out that
os.symlink
doesn't worked. I tried it with hard links,os.link
exists and executes.If I do it in pythonista shell it works as expected, that when I link to file(s) and change any of them the content of the other file(s) gets also updated.
For the files in the editor the hard links don't seem to work. Perhaps some caches in the app that come in effect here?
So I combined the suggestion from @omz with my idea and this works :-)The only drawback is on touch more, because I need to execute the file. Is the an auto run option in pythonista?
It was fun to do this, and awesome that pythonista allows this :-)