Skip to main content

Charming Python: Python for the PalmOS

Using Pippy for handheld app development

David Mertz (mertz@gnosis.cx), Reducing Agent, Gnosis Software, Inc.
author
David Mertz enjoys writing about everything that can be written at the margins of popular computer technology. David may be reached at mertz@gnosis.cx; his life pored over at http://gnosis.cx/dW/. Suggestions and recommendations on this, past, or future columns are welcome.

Summary:  Pippy is a port of (a subset of) Python to the PalmOS. With Pippy, Python programmers can create custom applications to run on Palm devices, as well as use Pippy as an interactive environment directly on the Palm. David evaluates the strengths and limitations of Pippy as a means of implementing Palm applications.

Date:  01 Jul 2001
Level:  Introductory
Activity:  2383 views

Let me introduce Pippy in the style of a good news/bad news joke. The good news about Pippy is that it allows a Python programmer to write and run programs right on the Palm. Moreover, with version 0.7, Pippy has gotten faster, more stable, and easier to use. The bad news is that, so far, Pippy is still fairly "bleeding edge" software, and a lot of the things programmers want in a development environment are planned for later versions, not available today. Still, Pippy gives you enough to play with now, and enables you to do some useful things without too much effort.

Installing Pippy

When installing Pippy, first download its executables and/or source archives. The source archive is available as a tarball, called pippy-0.7-src.tar.gz, while the executable-only distribution is called pippy_0_7.zip (or the same name with a .tar.gz, .sit, or hqx extension, depending on your platform). For most users, it's easiest to stick with the executable distribution. Let's look at that first.

Within a Pippy executable archive, you'll find a relative directory called ./pippy_0_7. Inside this directory are five files. Read the README -- as always -- and check out the LICENSE and NEWS files for the expected topics. Find files pippy.prc and pylib.prc. These are the ones that you want to upload to your PalmOS device.

How you upload these two files to your handheld varies depending on the desktop OS that you are running. However, users who have installed any additional applications to their PalmOS handheld will be familiar with the procedure. Under Windows and MacOS environments, you will usually use the "Palm Desktop" and its "Install" button. Under Linux or other UNIX-like platforms or OS/2, you will probably use the pilot-link utilities -- specifically the pilot-xfer program. This might look something like:


Listing 1. Transferring Pippy and PythonLib to the Palm

$ pilot-xfer /dev/cua1 -i pippy.prc
$ pilot-xfer /dev/cua1 -i pylib.prc

Once both PRCs are on your PalmOS handheld, all you need to do is run Pippy (I like to move it to a "Programming" Applications category, but this is a small convenience).

Compiling Pippy is a lot more work than just downloading the executables. There are two programming environments under which you might build Pippy. One involves getting PRC-Tools set up on your machine, and also Python 1.5.2 (exactly that version). Installing PRC-Tools itself is a complex game of chasing down library and compiler dependencies, and finding the right version of everything. All the details of doing that are not covered in this article.

For Win32 and MacOS environments, compiling Pippy might be easier. First you'll need to shell out some money for CodeWarrior. Next you'll need to download and successfully install the free tools Cygwin, PilRC, and Python 1.5.2 (a higher version of Python might work). While possibly less work than the PRC-Tools route, this route to compiling Pippy yourself is also not pain-free unless you happen to have a system with all the prerequisites.

If you do manage to build Pippy from source, you'll have the option of compiling in your own Python extension modules, and you will be able to import them by default. For this article, we'll just assume you are using the distributed executable version of Pippy. Fortunately, as of version 0.7, running custom code in the precompiled environment is a lot easier.


Working with Pippy

Pippy is an interactive environment, similar to the Python interactive shell, but owing even more to another PalmOS language/environment called LispMe (see Resources later in this article). For now, Pippy is just this interactive environment, not a way of creating standalone applications (unless you want to delve deeper into the source than I could). That makes a good start though. Let's see what it looks like:


Figure 1. A PalmOS handheld running Pippy
A PalmOS handheld running Pippy

Using Pippy involves entering Python commands. The picture illustrates this, but you can also create larger scale constructs like function definitions and classes.

One thing to watch out for in the interactive environment is that you need to eval each statement suite as soon as you write it. This can get a bit confusing, unfortunately, since some statements can get ignored in the interactive environment. For example, if you enter the below statements then press eval, you would almost certainly expect to see "4" printed:


Figure 2. A Pippy session with multiple statements at once
A Pippy session with multiple statements at once

Listing 2. Pippy session with multiple statements at once

x = 3
x = 4
print x

What happens instead is that nothing gets printed, and x is left equal to 3. Hopefully, this behavior will be improved for later versions.


Using stored programs with Pippy

Fortunately, rather than simply entering statements into the interactive environment, there is a much more practical and useful way to work with Pippy . Use the "Memo Pad" application to store Python programs you wish to run later. Create a Memo Pad category called "Python" (case is important), then store Python programs as memos therein. The one rule you'll need to follow is that each memo should start with a pound sign followed by the name of the Python script/module being implemented. For example, below is a simple program I wrote (entirely on the Palm, without touching a desktop computer):


Listing 3. A simple Python program written on the Palm

#go2.py
def
 go(data):
    from string import split
    add=lambda i,j: i+j
    lines=split(data,'\012')
    rows=[]
    for line in lines:
       fs=split(line)
       for i in range(len(fs)):
             fs[i]=int(fs[i])
       if fs: rows.append(fs)
    print 'Records:',len(rows)
    print '-----------------',
    i=1
    for row in rows:
        print '\nROW',i,
        cnt=len(row)
        print ' -count:',cnt,
        tot=reduce(add,row)
        print ' -tot:',tot,
        avg=tot/cnt
        print ' -avg:',avg,
        i=i+1

You may notice that I used shorter variable names and kept code lines short. I find it distracting when lines wrap on the Palm screen, since it makes it difficult to see which lines are wrapped for display, and which for program structure. Basically, this is a perfectly normal (albeit simple and boring) Python program. Let's look at an interactive session that uses this program.


Listing 4. Pippy Interactive Session using Memo imports

Python 1.5.2+ (#1, Jun 11 2001, 15:41:50)  [GCC 2.95.2-kgpd 19991024 (release)]
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam

import memoimp; memoimp.install()

from go2 import go
from data import data
go(data)
Records: 4
-----------------
ROW 1  -count: 5  -tot: 288  -avg: 57
ROW 2  -count: 4  -tot: 193  -avg: 48
ROW 3  -count: 7  -tot: 64  -avg: 9
ROW 4  -count: 4  -tot: 398  -avg: 99
from data2 import data
go(data)
Records: 2
-----------------
ROW 1  -count: 4  -tot: 173  -avg: 43
ROW 2  -count: 8  -tot: 45  -avg: 5

Notice the first line in particular. Before you can import from the Memo Pad, you need to import the memoimp module, and run its .install() method. I think the developers should make this the default for later versions, but in the meantime, it is handy to keep the first line in the clipboard (and in a memo to copy it there easily).

For completeness, let's take a look at what one of these "data" modules might look like:


Figure 3. A Memo Pad data file module
A Memo Pad data file module

It is easy enough to imagine that this little memo could be used to collect some sort of field data for which a handheld was ideal: count bird distributions for ornithological research; count widgets on each of the warehouse shelves; etc. You could easily enough add some more structure and formatting to the data, and parse out that structure accordingly. The example just produces some simplistic statistical data.


That's why they call it a beta

As I wrote at the beginning of this article, Pippy is still living at the bleeding edge. The stability is great, but Pippy lacks some pretty basic features. All things will come with time.

The first thing an astute reader will have noticed is that my sample application went through some odd contortions to get its input data. Why not just set up an input() or raw_input() loop, and collect the data there -- maybe processing it with each entry? The PalmOS has no concept of a file; in particular, it has no concept of STDIN, STDOUT, or STDERR. The print statement doesn't really go to STDOUT, but rather to the special console. The interactive input just isn't there at all.

One developer has suggested to me that it was possible to call custom forms from Pippy, where these forms were themselves created by other development systems. Using forms this way would be rather roundabout, and is not documented yet in any case. Look for something better in future versions -- maybe a simulation of STDIN and STDERR or some tools to easily produce Pippy-specific Palm GUI forms. For now, however, Pippy is most useful for batch processing (reminding me of my early -- and quite pleasant in retrospect -- experiences with IBM 360 punchcard queues).

Beyond interactive input, a number of modules and capabilities are still in the planning stages. The most important of these is probably floating point numbers! Unfortunately, this rather important basic type is still on the drawing board. Perhaps this has something to do with the floating-point architecture of the Dragonball processor. This is just a guess. I could be wrong.

Of significant importance are various missing modules. re isn't there, which would be a nice one. os is also missing, but there could be some good reasons for that one. Some other modules that are fairly standard are also gone.

Moreover, there are some additional goals for Pippy by its developers. Updating Pippy to the newest Python versions would be nice -- especially to include list comprehensions for conciseness. In addition, Pippy developers want to include Christian Tismer's Stackless Python patches to Pippy. This should improve performance quite a bit for the PalmOS hardware (and would be just plain cool).


Conclusion

The last portion of this write-up pointed to some fairly stark limitations of Pippy 0.7. One might read that as a criticism, but that is not my intent. I find Pippy to be one of the most exciting Python projects I have looked at. While Pippy is certainly not yet complete, it is proceeding in exactly the right way. The intermediate versions (like 0.7) are stable, and are improving in speed. Things are left out -- but they are called betas -- but what gets in there is well thought out and well implemented. This is the Python philosophy in action: first get it right, then add the bells-and-whistles. Still... maybe it is not too much to wish for a few bells in the near future.


Resources

  • Read the previous installments of Charming Python.

  • Visit Pippy's home page and download Pippy.



  • PRC-Tools is the Linux (and other operating systems') way of building C/C++ PalmOS applications. It consists of a bunch of related free software tools that let you target the Palm's 68k (Dragonball) CPU and hardware environment. You can install PRC-Tools from the PRC-Tools home page.



  • Metrowerks CodeWarrior for Palm OS Platform is an excellent IDE and compiler for PalmOS development, at least if you use a Win32 or MacOS machine. CodeWarrior is pretty much the "standard" development tool for PalmOS; it's the tool that Palm Computing uses to develop the OS, for example. CodeWarrior is a commercial product, and you will probably have to pay money to get it (the amount depends on the license details).



  • Another language available for the PalmOS provided an inspiration for Pippy's interactive interface. Check out LispMe.



  • Read "Charming Python: Inside Python's implementations" on developerWorks, where David interviews Christian Tismer on Stackless Python.



  • Browse more Linux resources on developerWorks.



  • Browse more Open source resources on developerWorks.



  • Browse more Wireless resources on developerWorks.



About the author

author

David Mertz enjoys writing about everything that can be written at the margins of popular computer technology. David may be reached at mertz@gnosis.cx; his life pored over at http://gnosis.cx/dW/. Suggestions and recommendations on this, past, or future columns are welcome.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Linux
ArticleID=11132
ArticleTitle=Charming Python: Python for the PalmOS
publish-date=07012001
author1-email=mertz@gnosis.cx
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers