All About Symbian - Nokia and Samsung hardware and software reviews

Book review: Mobile Python

Published by Steve Litchfield at 11:08 UTC, November 14th 2007 under Hardware in General, S60 3rd Edition|| 9 Comments / Post New Comment
Steve Litchfield looks at a new book on PyS60 - who's it for and is it any good?
Version Reviewed:
Score: 84

If you have even the slightest interest in creating applications for S60 smartphones then you'll have heard of Nokia's open source port of Python. Essentially this takes the industry standard (and supremely flexible) Python programming language (itself open source, i.e. free and extensible) and adds a huge number of phone-specific modules and functions, plus a real-time interpreter.

If you remember Psion's OPL, the simple language that enabled applications to be created quickly for their palmtops and later for Nokia's 9210 and 9500 (and assorted other Symbian OS phones), then there are distinct similarities in the overall concept. Python differs from OPL in its form and function however. It's a harder language to get to grips with, not least because its object-oriented, but on the plus side the PyS60 modules mean that almost anything your smartphone can do is available in function form with a minimum of effort from Python.

Mobile PythonJuergen Scheible, one of the authors of Mobile Python, new from Wiley, has been a leading evangelist for PyS60 since its inception, so he makes the natural lynchpin here. Ville Tuulos is a new name to me, but there are plenty of others from the Python and Symbian worlds who also seem to have made contributions here.

Mobile Python's subtitle is 'Rapid Prototyping of Applications on the Mobile Platform', but as with the earlier book on OPL, which had a similar title, a substantial number of Python programs will end up being THE applications, not just prototypes. It's important to get your head around the sheer power of PyS60 - about 20% through the book, there's a ten line code example that's a fully working SMS Inbox search tool. In ten lines! The richness of the Python language and the PyS60 modules thus make writing a book teaching it all something of a challenge.

But it's a challenge that has been taken up with gusto by the two main authors. Mobile Python is NOT a reference book though - as the book goes on, there are more and more references to the main PyS60 documentation (a set of PDF files on the web). And it's NOT a book for beginners. Uncle Tom and your sister will give up after chapter 3 and so will you unless you've done some programming on other computers in the past. Although there are boxed 'Python Language Lessons' every so often, these are intended more for alerting clued up home developers to the way in which Python does things.

I'm coming to PyS60 from OPL, C and Fortran (all pretty old procedural languages) and found myself making reasonable progress but starting to struggle a little once into the meat of the book. The problem isn't with the book itself, it's with the Python language and the PyS60 implementation of it. Python is just so darned flexible that modules and functions (and this goes for the PyS60 parts too) have in places been implemented seemingly at random, with little thought for consistency. So some modules have sub functions, some have sub-sub-functions, some expect certain parameters or return different values and, to be honest, trying to keep it all in your head is just about impossible. There are about half a dozen ways I can think of to do 'Hello World' in Python and twice as many ways of implementing a simple event-driven application framework, none of which are any more 'official' than any other. It's a bit overwhelming, to say the least.

Mobile Python approaches the problem in 'tutorial' manner, introducing concepts and example code hand in hand, so that you're always building code snippets which work and do something useful, hammering home the message about Python being a great language for creating applications quickly. And you'll be impressed how efficiently your S60 smartphone's systems are accessed. At one point in chapter 4, a complete SMS server game is created (Hangman), which users sending in guesses by SMS and receiving results in the same way. All from Python on your phone in less than 50 lines of code! The difficulty level of the PyS60 code rises fairly rapidly as the chapters progress, which is why you'll need to have some prior programming experience and/or a real aptitude for this sort of thing. 

Python bookThe example applications (all thankfully downloadable from the book's web site - the typing's not that arduous, but it does help reduce typos!) that come thick and fast throughout the bulk of the book should give you an idea of the PyS60 functionality which is demonstrated:

MP3 player / Camera with viewfinder / UFO game / GSM cell locator / Vocabulector (a language learning aid) / Bluetooth chat / GPS reader / Photo uploader / HTTP server / MopyMaps (client for Yahoo maps) / EventFu (web 2.0 event guide) / MobiLenin (multi-device video interaction) / MobileArtBlog (an arty image composition gadget) / Roombatics (control of the Roomba vacuum cleaner)

Most of the latter examples above are existing real world applications and included for interest, to see how they work, rather than specially written code for the book itself. As said above, Mobile Python doesn't pretend to be a reference book - I guess that would make a good followup - and for every tasty function that gets introduced I'm also tempted to wonder where the function fits into the overall module, what the other parameters are that aren't mentioned, why a function is called in a specific way, and so on. As many questions are raised as examples given.

But I'm not going to let that spoil my appreciation for Juergen and Ville getting this book out in the first place, full credit to them for managing to find the time, resources and backing in an age that so often publically endorses open source software but rarely puts real money or effort into doing anything with it.

Extras with the book include an appendix on Platform Security and application (SIS) building, one on setting up a 'Bluetooth console' (debugging PyS60 code from a PC), another with advice on debugging code, plus some tables and a reasonable index to all the major modules and functions mentioned.

That Mobile Python is the best book on PyS60 isn't in doubt, seeing as it's the only one. But as someone who loves to tinker with Python in my spare time, I've definitely found my imagination and enthusiasm fired - and I suspect this was exactly Juergen and Ville's aim.

Steve Litchfield, AllAboutSymbian, 15 Nov 2007

Python book open

Review Discussion

9 Comments / Post New Comment

Unregistered
This book looks very interesting and I will probably buy it, but I was wondering if someone familiar with PyS60 knew if it has a module to aid in using the accelerometer for an appication.
slitchfield
There isn't a module for this yet, but I'd place good money on it arriving in due course....
Unregistered
Does anyone know if it's actually possible to develop/code directly on a nokia S60 phone? Rather writing and compiling on a desktop PC.
Using a fold out bluetooth keyboard, and your phone, can you program on the go?
there are a few packages available for PocketPC development on the device itself, it would be great if there was something like this on the nokia's.
Unregistered
I do code editing on the go in Python. The Python for S60 implementation runs Python code against the run time interpreter. You just need something to edit the .py files on the phone. Luckily, someone has done a Python indenting editor for S60 called PED.

Try this: http://discussion.forum.nokia.com/fo...d.php?t=108617

http://homepage.rub.de/Arkadiusz.Wahlig/Ped/
Unregistered
You are asking for AccelerometerPlugin for PyS60 ?
Nokia has published the sensor module for using accelerometer from Python since 16 October 2007 (before the buzz about accelerators in N95 !) but it works actually with the following models : N82 , 5500 , N95 8GB , N93i 20.0.084 (XYZ axes)
N95 classic (only with X and only 4 values : right , left , top , bottom) like RotateMe from Samir


For full support for this one you have to use AcceleratorPlugin from NRC plus the aXYZ module (that I have developped since 13 November 2007 (before you wrote this article :-) More than 70 downloading in 3 days !
You can download it at sourceforge search about pyed or search discussion about aXYZ on the Python Forum Nokia DiBO
You can ie use your N95 for making Lightsaber in PyS60 and look at Cube example
at the DiBo

Sorry I can post links because I haven't got enough posts (10) :(

Cyke64
Unregistered
Yes, I've written quite a bit of Python on my N93, you just need a good editor, such as EasyEdit, and a copy of the API doc in a useful format (mobipocket for example). As Steve said, Python might be quite intimidating at first for people from a C/Basic/OPL) background, and I found the best way was to start from a working example and tweak it bit by bit. The ease of internet connectivity alone pays its bus fare - http post/get is simple, for example, so if you have a monster server sitting at home you can use it for beefy processing effort, bulk storage and serving up files in convenient formats, etc.

BTW the callback to detect the auto-rotation of the screen on the N93 when you do the old Rubik's Cube maneouvre doesn't seem to work, you have to poll for it instead.
jukkaeklund
In case you want have a web server in the phone to serve Python stuff, you know where to find it :)
cyke64
Quote:
Originally Posted by Unregistered View Post
Yes, I've written quite a bit of Python on my N93, you just need a good editor, such as EasyEdit, and a copy of the API doc in a useful format (mobipocket for example). As Steve said, Python might be quite intimidating at first for people from a C/Basic/OPL) background, and I found the best way was to start from a working example and tweak it bit by bit. The ease of internet connectivity alone pays its bus fare - http post/get is simple, for example, so if you have a monster server sitting at home you can use it for beefy processing effort, bulk storage and serving up files in convenient formats, etc.

BTW the callback to detect the auto-rotation of the screen on the N93 when you do the old Rubik's Cube maneouvre doesn't seem to work, you have to poll for it instead.
What do you mean by poll it ?

Cyke64
pintofale
@cyke64

By 'poll' I mean check the 'size' method of your 'canvas' to see if it's (320,240) or (240,320). This is fine if you're constantly refreshing the screen, like Nokia do in their 'ball' example.

I did notice some other sizes but I think this is do do with a delay between re-orienting the screen and switching (back) to 'full screen' mode, which is a python VM problem and not visually noticeable.

9 Comments / Post New Comment

Copyright Notes || Contact Us || Privacy Policy