Python
Mailing
List - The Python-Macintosh SIG is used to foster discussions about
Mac-specific issues of Python. The list is primarily meant to discuss
design and implementation of Python on the Mac, and possibly coordinate
the actual implementation work done.
Also check the Python books; Tkinter has been the default GUI
for Python for many years and ships with it so many Python manuals also
cover it.
The mac does not have tcl/tk on it by default; you must install tcltkaqua
first.
After this is loaded, you can open the Package Manager and install
_tkinter
Python on the Mac
MacPython-
Downloads and documentation, including IDLE, Python Launcher and the
Package Manager
Tkinter on the Mac:
The mac does not have tcl/tk on it by default; you must install
tcltkaqua
first.
After this is loaded, you can open the Package Manager (see MacPython
entry above) and install
_tkinter
You must use pythonw
instead of python for python scripts which use Tkinter.
You cannot use the Python IDE for applications with Tkinter.
You can use IDLE with Tkinter, but only if you make the changes
below.
Make sure that all old .pyc files are removed before trying to
use the toolkit or other package. .pyc files from other machines will
not work properly on Windows.
Python on Linux
Be careful what you use to unpack (unzip, untar) tgz files (like
the
RLtoolkit). Used zcat with tar messes up the __init__.py files. They
are saved as __init__.py.bin files and are gibberish. I'm not quite
sure why this happens. Perhaps someone can fill in a method here that
works well without this problem.
SubEthaEdit-
edits, colorizes and prints code, but does not run it.
IDLE the
standard IDE
for Python - colorizes, runs, debugs, prints - does it all.
IDLE requires Tkinter: make
sure
tk is installed on your
machine (see tkinter section above)
Macintosh IDLE:
Make sure you have
the MacPython download (from above) installed. IDLE will be in
folder /Applications/MacPython-2.3
The key bindings are initially set for Windows. To change
this, go to the Options menu
and select Configure IDLE. A
window will pop up with several tabs on it. Choose the Keys tab and select the IDLE Classic Mac setting; then
click Apply and Ok.
To use Tkinter in python scripts: change IDLE
to
start with pythonw, not
python:
From a terminal window, go to
/Applications/MacPython-2.3/IDLE.app/Contents/Resources/idlelib
Do one (or both) of the following:
Edit (e.g. vi) idle.py file to
use pythonw instead of python (first line). The first line should look
like:
#!/usr/bin/pythonw
Start up Python Launcher (same location as IDLE
/Applications/MacPython-2.3)
tell it to use
pythonw as the interpreter (/usr/bin/pythonw)
tell it NOT to allow override #! from a script.
Save the file (modified or not) as idle.py somewhere
useful for you
(desktop, your home directory, etc).
Do Get Info
(cntl click gives you a menu; select Get
Info
from there) on the file. Under Open With, choose PythonLauncher.
Close the Get Info window.
Now you can double click on this idle.py file to get
IDLE
started (hint - move it into your dock in the document area and you
will be able to click on it and start idle from there).
DO NOT try to start IDLE using the Macintosh
application
under /Applications/MacPython-2.3. It will start with python, not
pythonw, even with the changes you have made.
To get interactiveness with tk scripts (i.e. build
interactive windows and still be able to use the shell):
Windows XP: c:\Python23\Lib\idlelib (need to
check this)
Now when you use gMainloop or tk's mainloop functions,
you will get the message:
'IDLE: now running in event loop'.
You can
now use your windows interactively, and type commands into the shell
and
have them run.
Python is not as fast as c or Lisp, but there are some things that can
be done to speed it up. Please add to these as you discover them!!! And
remember, you can call c from Python, so that is an option too!
Some hints
While loops are faster than for loops
Use xrange instead of range on for loops for greater speed
Python profiler - shows you where you are spending the most tile
(included in python distribution)