Python is an open source interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for rapid application development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse.
The main Python homepage is at http://www.python.org/
Python is developed mainly for the Unix platform. Because the full source code is available, ports to many other platforms exist nowadays. These include Macintosh, Windows and AmigaOS of course! AmigaPython is the Python version for AmigaOS. Not only is it largely compatible with the 'mainstream' Unix Python version, but it is also a real Amiga program by adding some exciting Amiga features to it:-
I intend to make sure that at the very least all of the examples in O'Reilly's Learning Python will work, so please consider buying that book by clicking the Amazon link in the sidebar.
Don't forget to Save Target As... or equivalent, modern servers and browsers don't always know .lha means binary!
AmigaPython and this website are:
Copyright (C) 2005 Tim Ocock, Copyright (C) Irmen de Jong (used with permission).
For license terms, see the front page of my Amiga section, here
Python was originally ported to the Amiga by Irmen de Jong. He did a great job adding Amiga specific functionality, including ARexx support (allowing you to use Python as an alternative to ARexx amongst other things!). However, Irmen no longer has an Amiga and requested someone take on the project on his original website here
http://www.xs4all.nl/~irmen/amigapython/
I (Tim Ocock) took on the challenge, since I wanted to refresh my memory of Amiga programming, give something to the Amiga community that has held on for so long, and because I seem to be one of the few people with the SAS/C compiler that Irmen used (I bought one of the last sets, the binderless ones they sold at great discount). Irmen gave me some useful advice and support, and permission to continue his work and incorporate his original website in my own.
Python is free but please support my Amiga software development in general. You can do that in a number of ways:
You can contact me here amiga@monkeyhouse.eclipse.co.uk
You can find out what's new in Python 2.3.3 at the main Python website here. The examples there all work.
Currently it is compiled it with SAS/C 6.58 for the 68020 CPU, and AmigaOS 3.0 or higher with AmiTCP/Genesis and 2MB of memory. I think this is a fair baseline these days. The full source code is available so in theory you could build a 68000 OS 2.04 version with no networking. But permission is not granted to release your own builds - instead send them to me.
AmigaPython and AmigaOS4
Python is designed to fill the niche between shell scripts and full on programs - and it does it very well - but not as well perhaps as ARexx, since it needs 10x as much memory. However, on today's computers that's not so much of a concern. Thus it would suit OS4 quite well as an alternative to ARexx, especially since AmigaPython already supports ARexx. I understand Hyperion have previously considered and dismissed Python, for the time being, as they have more than enough to do, so I don't blame them at all.
I am hoping that a 68K to OS4 cross compiler will be released sooner rather than later. I am unlikely to be able to justify getting an OS4 capable computer for the foreseeable future. But I'd like to be able to build a version for all those who have supported Hyperion. The sad truth is that there won't be any native software for AmigaOne owners unless someone makes it easy to develop for, and that means making tools and documentation available to all.
If you want to see native software on OS4, please consider making a donation to this project, using the Paypal link in the menu, and to other projects that you would like to see on OS4.
Don't forget to assign Python: to your python directory first!!
Check the distribution for a more detailed ToDo list and FAQ
Roadmap
I will make a Beta release when the test suite completes without anything other than errors due to modules not available on the Amiga. At this stage I will complete testing of the examples from the book, and begin to fix any problems I find there.
The final release will then be made when all the examples from the book are working, and I have integrated the documentation to provide online help. Only after this will I begin work on support for Tkinter GUIs.
I will also be using the RSS feedparser.py module to test the interpret, as I would very much like to provide RSS news reading on the Amiga.
Wishlist
Python isn't very Amiga like in the way it integrates with it's host system. It's basically one huge executable and each Python program needs it's own instance of the interpreter. Most of that 1MB file size is taken up by the builtin function modules which are statically linked. On Unix systems, they can be dynamically loaded using the dlopen() which is a very inelegant way of using MMUs to have a virtual contiguous address space. Apparently this might be available in OS4, but it's not very efficient. A much better approach would be one that allows Python to be a resource shared across the system, like ARexx, but I don't know how possible that will be. Ideally I would like the following:
AmigaPython Example: 'finger' for ARexx
Enough talk. Let's see some Python to give you an idea. Note that this example is for AmigaPython only because it uses the ARexx extension!
A finger tool for ARexx - just like the 'finger' command you know to find out about a user. Is it possible? YES! First let's make a ARexx host in Python which provides us with a FINGER ARexx command. Here is the source:
# Python interface to the Internet finger daemon.
import sys, string
import socket
import ARexx
FINGER_PORT = 79
def finger(host, args):
print host,args
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(host, FINGER_PORT)
s.send(args + '\n')
reply=''
while 1:
---buf = s.recv(1024)
---if not buf: break
---reply=reply+buf
---return reply
# The function to handle the arexx commands,
def cmd_dispatcher(host,msg,cmd,args):
try:
---if cmd=='FINGER':
------msg.result=finger(args['HOST'],args['USER'])
except socket.error,string:
---msg.rc=ARexx.RC_ERROR
---msg.rc2=string[0]
---return 1
h=ARexx.host()
h.setcommand('FINGER','HOST/A,USER',{'USER':''},cmd_dispatcher)
print 'The ARexx port name is ',h.name
h.run()
(N.B. In Python, indentation matters. Thanks to the limits of HTML, the above code doesn't show the correct indentation. When copying, remember to add 3 blank spaces in place of --- )
We have an interface to the finger daemon in Python, and a full-fledged ARexx host which provides us with two commands: HELP and FINGER. The last line (h.run()) activates the message loop which will handle all commands until you press CTRL-C. HELP is a default command which is provided by the ARexx.host class for you, including a simple implementation. I defined the FINGER command with arguments:-
FINGER HOST/A,USER
The hostname to finger is necessary while the user name may be omitted (it defaults to the empty string). Now, let's see how we can access this ARexx host when it's running:
/* Finger client in ARexx */
options results
address 'PYTHON' /* fill in your port name here */
say 'FINGER @localhost...'
FINGER 'localhost'
say RESULT
say 'FINGER root@localhost...'
FINGER 'localhost root'
say RESULT
HELP FINGER
say 'The help string on the FINGER command is:' RESULT
HELP BOGUSCOMMAND
if RC=0 then do
say RESULT
end
else do
say 'An error occured for HELP BOGUSCOMMAND:' RC2
end
Voila! Of course you could now use AmigaPython's ARexx capabilities to write another Python script which duplicates this ARexx script's behavior and calls the ARexx host (AmigaPython running the Python script above in another shell), effectively using ARexx as an interprocess communication layer. I'll leave this as an exercise to the reader.
Of course, time permitted, as AmigaPython evolves this list may grow! Suggestions are welcome. For GUI support, I would rather implement Tk or wxWindows than do something Amiga specific, but that is a lot of work. I suggest using AWNPipe for GUI's for now.
AmigaPython includes very powerful ARexx support. Irmen added a low-level builtin module ( ARexxll ) and a high-level module (ARexx , written in Python). You're able to add an ARexx port to your Python programs in no-time, and you're also able to control other applications from Python by sending them ARexx commands to their ARexx port. The ARexx module implements:
For more powerful operation under AmigaDOS, and because it is needed for the ARexx implementation, there are two additional modules. The first is the low-level builtin module Doslib, and the other, the Dos module, is written on top of it (in Python). They work together much the same as the strop and string modules do: you don't use the builtin one directy but rather the higher-level module. So, you will only need to use the Dos module which provides the following:
Of course AmigaPython supports the Workbench. You can:
And as you might expect: tooltypes and multi-selected icons are converted to command line arguments. Python never knows it was launched from the Workbench!
For total control and flexibility there is a module ( environment ) that implements various functions to control your environment variables from within Python. AmigaPython discriminates between Global environment variables (in ENV:) and Local environment variables (shell-local). You're able to read, write and update both types of variables. For portability, os.environ contains both types.
Finally there are some small enhancements scattered throughout the program, but mostly in the amiga module. For instance, there is a very fast CRC-32 checksum function. In the select module, there is an enhanced version of the select function. The AmigaPython version is able to wait not only on network events, but also on DOS signals, with or without a timeout!
The current release is: 2.3.3 build 2 (alpha release)
Previous releases are available on Aminet:
Python 2.0, build 1, released October 29, 2000. Features include:
Based on the 2.0 final Python source
AREXX support: ARexx module
Direct AmigaDOS support: Dos module
Workbench support (accepts Workbench icon tooltypes, arguments and scripts)
Other Amiga specific enhancements
First fully Unicode aware AmigaDOS application (as far as I know)
Contains fast XML parser (Expat)
Documentation for Amiga features
Python 1.6, build 1
Python 1.5.2, build 5
For the 1.5.x and 1.6 versions, currently no bugs or problems are known.
The 2.0 version appears to have some stack related problem which seems fixed by using a BIG stack (400Kb+). (Fixed in 2.3.3)