||Reinforcement Learning and
Information and Resources
The ambition of this
page is to provide information and links for using Python.
Python Documentation, Tutorials and General Information
Tkinter (Python version of tk) (GUI)
Introduction to Tkinter (html)
- 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
- 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
Python on the Mac
Downloads and documentation, including IDLE, Python Launcher and the
- Tkinter on the Mac:
- The mac does not have tcl/tk on it by default; you must install
After this is loaded, you can open the Package Manager (see MacPython
entry above) and install
- 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
- IDLE on the mac
Python on Windows XP
- 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
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.
Mixing Python and C
Other Python Packages
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
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
- 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
start with pythonw, not
- From a terminal window, go to
- 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
- Start up Python Launcher (same location as IDLE
- 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
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
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
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):
- Download a new run.py
file from Jason
- Replace the run.py
file in idlelib with the new one. The
idlelib location depends on your machine. For example:
- Macintosh: there are two places to replace the run.py
file (use Terminal to do this)
- Linux Redhat 9: /usr/lib/python2.3/idlelib
- Windows XP: c:\Python23\Lib\idlelib (need to
- Now when you use gMainloop or tk's mainloop functions,
you will get the message:
'IDLE: now running in event loop'.
now use your windows interactively, and type commands into the shell
have them run.
of Python Editors and IDE's
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)
- import profile
- profile.run('python command')