Mac OS:
- Idle:
After installing Python, the default app for .py files seems to be Idle, so a double-click on a .py file shows this python code within Idle, edit it, then run it by pressing F5.
- WingIDE:
I like WingIDE (101) a lot. On Mac it's an X11 app (a graphics system that's different than the Mac's native Quartz) so it doesn't support some of the core Mac conventions, e.g. drag and drop. The (only?) way to open a .py file in Wing is to open the WingIDE.app application (I use Spotlight: type Wing - it finds WingIDE.app - hit Return). Once running, use Open... (or File - Open), this brings up a basic file manager (but not Finder!), in which you have to navigate to the folder of your .py file. Once opened, Wing will keep the .py file until you explicitly close it (i.e., if you quit Wing and re-start it, the file will still be under it's own tab) and there's a recent file history. So getting back to a file you've opened in the past is easy but opening a file for the first time is a bit clunky.
Luckily, you can set the default folder (directory) in which Wing's file manager will open, it's under Edit - Preferences - Files:General. The settings depend a bit if your .py files tend to be in different folders. I like "base on current file" (i.e. it opens the folder of the file in the current active tab) as I have many folders with .py files. If you tend to have you files in the same folder use "folder of the last opened .py file" or "project's home", which seems to be the user's home (/Users/chris), or you can set it to a specific folder, like /Users/chris/Desktop/python-code.
- Other:
Maybe you want to use another editor (or a python launcher) instead of Idle. As I cannot seem to find a global way of telling MacOS "use this application for all .py file" I've created a couple of icons of editor application in my Dock (find the .app file in Applications and drag it on the Dock, works also for the Finder toolsbar). Now, if want to open a .py file in VIdle or Vim instead of Idle, I can drag & drop it on the icon in the Dock (or Finder). Again, drag & drop does not seem to work for Wings.
- Executing a .py file:
There's an application called Python Laucher.app (note the space) in your /Applications/Python X.X/ Folder, this will "simulate" the running of a .py file inside a terminal. I've also made a Dock icon for this application, now when I want to run a .py file I simply drag & drop it on the Python Lancher.
Windows:
- Editing a .py file:
Assuming that the installation of Python (or the editor, IDE, etc.) puts an "Edit with ..." entry in the right-click pop-up box, I like to use on a file.
- Executing (running) a .py file:
Double clicking on a .py file should execute it, if the console pops up but closes again, remember to put a raw_input("Hit Enter to quit") at the end. - You could also wrap a shortcut around the .py file that takes care of feeding it to the python interpreter (i.e. the equivalent of a RunMe.sh shell script or a RunMe.bat batch file). Make a shortcut in the same folder, in Target: put the python interpreter executable's full name followed by the .py file and blank out the Start In: field (that seems to mean "start in the shortcut's folder":
No comments:
Post a Comment