Print
O'Reilly Book Excerpts: Nokia Smartphone Hacks

Run Python Scripts on Your Nokia Smartphone

Editor's note: If you enjoy this sample hack from Nokia Smartphone Hacks, be sure to check out the book. There are many more such hacks that will show you how to take full advantage of Nokia's powerful smartphones. Among the cool hacks the book covers are how to unlock your phone so that you can use it with any carrier, how to watch DVD movies on your phone, how to check your email and browse the Web, how to post to your weblog from your phone; how to transfer files between the phone and your computer, and much more.

Use the Python scripting language to develop small hacks for your Series 60 device.

Related Reading

Nokia Smartphone Hacks
Tips & Tools for Your Smallest Computer
By Michael Juntao Yuan

While Java and Symbian C++ are powerful programming languages, their learning curves are too steep for most smartphone users. Most users do not need a full-blown programming platform to develop small hacks for their phone. A scripting language is the perfect tool to automate simple tasks and perform simple logical processing.

Python is a widely used scripting language in the computer world. It is easy to learn and supports object-oriented program construction. Nokia provides support for Python on most of its Series 60 devices.

TIP: Speaking of running scripting languages on Nokia Series 60 smartphones, there is an unsupported Symbian port for Perl 5.8x and 5.9.x. You can find the installation package and usage instructions from this mailing list posting from a Nokia engineer.

Install the Python Environment

The current Nokia phones do not come with the Python runtime environment preinstalled. You have to download and install Python yourself.

You can download the Python for Series 60 package from the Forum Nokia web site under the Series 60 Platform → Tools and SDKs category. The download package is a zip file with the .sis installation files, documentation, and example code. Make sure you read the Getting Started document in the download bundle to choose the correct .sis file for your phone. Then, you need to install the extracted .sis file to the phone, following the instructions in "Run Symbian Applications" [Hack #17]. The .sis file installs the following components to the phone:

  • A Python language interpreter

  • The necessary libraries (DLL files) to run Python applications

  • A plug-in for the phone to recognize Python scripts and Python libraries downloaded from the Internet or embedded in incoming messages

Once the Python runtime is successfully installed, a Python icon appears in the Main menu.

Run Python Scripts

Click the Python icon to open it and then select Options → Run script. You should see a list of installed Python scripts and applications (see Figure 3-10). If this is the first time you've run Python, the scripts that appear will be the demo scripts from Nokia. You can try any of them. The filebrowser.py script is a good start. It allows you to browse the filesystem on the Series 60 smartphone, similar to what FExplorer does [Hack #20]).

Install Python Scripts

Of course, ultimately you want to install and run your own Python scripts on the device. To do that, you can put the Python script (with the .py filename suffix) on a web page and download it using the Services browser, or you can simply send the script to the phone via Bluetooth. The phone recognizes the Python script and prompts you to install it. Once the script is installed, it becomes available under the Python script list and you can run it from there. Figure 3-11 shows the process.

Figure 3-10
Figure 3-10. Running an installed Python script

Figure 3-11
Figure 3-11. Installing and running a Python script from a file sent via Bluetooth

The user-installed scripts are placed in the C:\System\Apps\Python\my\ directory (or in E:\System\Apps\Python\my\ if Python for Series 60 is installed on the MMC card; see Figure 3-12). You can delete those files to delete Python scripts.

Figure 3-12
Figure 3-12. The path to an installed Python script

Pages: 1, 2

Next Pagearrow