Getting Started With Python 1 0
Getting Started With Python 1 0
Python for
Series 60 Platform
Forum.Nokia.com
Disclaimer
The information in this document is provided "as is," with no warranties whatsoever, including any warranty of
merchantability, fitness for any particular purpose, or any warranty otherwise arising out of any proposal,
specification, or sample. Furthermore, information provided in this document is preliminary, and may be changed
substantially prior to final release. This document is provided for informational purposes only.
Nokia Corporation disclaims all liability, including liability for infringement of any proprietary rights, relating to
implementation of information presented in this document. Nokia Corporation does not warrant or represent
that such use will not infringe such rights.
Nokia Corporation retains the right to make changes to this specification at any time, without notice.
License
A license is hereby granted to download and print a copy of this specification for personal use only. No other
license to any other intellectual property rights is granted herein.
Contents
1 Introduction................................................................................................................................................ 5
1.1 Scope ............................................................................................................................................................5
1.2 Audience......................................................................................................................................................5
1.3 Typographical Conventions...................................................................................................................5
2 Python for Series 60 Platform ................................................................................................................ 6
2.1 Delivery Package.......................................................................................................................................6
2.2 Development Environment ...................................................................................................................6
3 Installing Python for Series 60............................................................................................................... 7
3.1 Installing on a Series 60 Mobile Device.............................................................................................7
3.2 Installing into the Series 60 SDK .........................................................................................................8
4 Using Python for Series 60 ...................................................................................................................... 9
4.1 Starting Python for Series 60................................................................................................................9
4.2 Running a Python Script.........................................................................................................................9
4.3 Running an Interactive Console........................................................................................................ 11
4.4 Writing Your Own Scripts.................................................................................................................... 11
4.5 Installing a New Script......................................................................................................................... 12
5 Python Installer........................................................................................................................................14
6 Uninstalling Python for Series 60........................................................................................................15
6.1 Uninstalling Python for Series 60 from the phone..................................................................... 15
6.2 Uninstalling Python for Series 60 from an SDK............................................................................ 15
6.3 Uninstalling Extensions and Scripts ................................................................................................ 15
7 Terms and Abbreviations ......................................................................................................................16
8 References .................................................................................................................................................17
Change History
1 Introduction
Python is a simple, consistent and effective programming language. It is also open source, and it can
be used for application development, prototyping, and teaching. The Python for Series 60 Platform
(Python for Series 60) simplifies application development and provides a scripting solution for the
Symbian C++ and Series 60 APIs. This release is based on Python 2.2.2.
The current version of the Python execution environment is simply a Python script that makes it
possible to run other Python scripts to be found in the Python folder. The execution environment also
enables the users to initiate an interactive Python console session, which is also implemented as a
Python script. In addition, the Python execution environment creates a text console that is connected
to interpreter’s standard text output streams. This setup is useful for Python for Series 60 environment
evaluation and script development. Python Installer and interactive console support have been
implemented entirely in Python. Note that to the end-users, the Python applications may look like any
other applications.
1.1 Scope
This document provides the information required to install Python on the Series 60 SDKs and on the
Series 60 phones (models N-Gage QD, 6600, 7610, and 6630), as well as information on creating,
installing and using Python scripts and programs.
1.2 Audience
This guide is intended for developers looking to create programs that use the native features and
resources of the Series 60 phones. Users of this guide should be familiar with basic programming and
preferably also with the Python programming language.
Python for Series 60 uses the following development environment and software:
• Python, current release based on Python 2.2.2
• Symbian Series 60 1st or 2nd Edition SDK
• Python for Series 60 Platform
• A text editor, for example:
IDLE (Integrated Development Environment) (included in all Python versions from
http://www.python.org/)
• Connection between the mobile device and a PC (Infrared, Bluetooth, USB, or a cellular connection
with GSM or UMTS)
For more information on programming with Python, see Programming with Python for Series 60
Platform [2] and Python Web site at http://www.python.org/.
Close all applications in your device before you start the installation. After installation, an application
called Python, which launches the Python execution environment, is visible in the phone’s (or an
emulator’s) main menu.
There are two ways of installing the Python for Series 60 files on a Series 60 device:
• Nokia PC Suite software, see http://www.nokia.com/ Web site for more information.
• Infrared or Bluetooth
If you use Nokia PC Suite and have associated files of SIS type with the PC Suite application, click the
PythonForSeries60.SIS. or PythonForSeries60_pre_sdk_20.SIS (see Table 1). The
execution environment is installed automatically (you may have to confirm the file transfer from the
phone).
You can also install Python for Series 60 directly from a PC using the Infrared port or Bluetooth.
Select the Python icon to start Python. Select Options > Run script to test Python on your phone.
Follow the instructions in Chapter 4, Using Python for Series 60.
When you download the SDK from the Internet, note that you must choose a Nokia, Borland, or
Microsoft edition of Series 60 SDK for Symbian OS. The current release does not support CodeWarrior
editions.
You may install the Python emulator and sample scripts to all the supported SDK versions separately.
Choose the installer from the following list:
• Python_1_0_for_Series60_SDK_1_2.exe – installer for SDK version 1.2
• Python_1_0_for_Series60_SDK_2_0.exe – installer for SDK version 2.0
• Python_1_0_for_Series60_SDK_2_1.exe – installer for SDK version 2.1
• Python_1_0_for_Series60_SDK_2nd_ed_FP2 – installer for SDK 2nd Edition Feature Pack
2
Start the installer program and follow the instructions. The installer asks for a folder to install the
customer documentation and utilities, which are equal to all SDK versions.
The installer copies the emulator files and the sample scripts into the directory
<EPOCROOT>\Epoc32\Release\wins\udeb\z\system\apps\PYTHON
In the directory, there are some sample scripts that you can copy by a different name and then edit
the copies. Note that you do not have to restart the Python execution environment if you modify the
scripts.
Using the emulator is like using Python for Series 60 on the phone. For more information, see Chapter
4, Using Python for Series 60.
For more information and for guidelines on how to extend Python for Series 60, see Programming
with Python for Series 60 Platform [2].
You can use Python for Series 60 from the phone UI in two different ways: either by running the
console, or by launching a script. Both options are available in the Python execution environment. It is
also possible to install individual scripts to the terminal in a way that makes them appear in the main
menu as native applications. In such a case, the Python interpreter is not visible to the users.
Using Python in the emulator is mostly similar to using it in a phone. The instructions given in this
chapter apply for both phone and emulator, except for a few details that are specifically pointed out.
Tip: If you use Python regularly, you may want to move the Python icon up towards the top of the
screen for easier access.
2. To run the interactive Python interpreter console, select Options > Interactive console.
3. To launch a Python script from a menu, select Options > Run script.
4. To find out more about Python, select Options > About Python.
To start Python for Series 60 on the SDK, launch the debug version of the emulator. Select the Python
icon on the emulator’s main menu.
To get a list of Python scripts, choose Options > Run Script (see Figure 2). This dialog displays all the
scripts currently installed in the environment.
default.py and interactive_console.py are the scripts that implement the Python
application you are currently interacting with. For this reason, they are fundamental and should not
be removed.
filebrowser.py is a simple file browser for the device that allows you to browse directories and
open files that have a handler associated with them in the system. Note that you can press the
navigation key to open or delete a file.
Note that it is up to the individual script to decide how it behaves on Exit; it may choose to let the
entire Python execution environment exit. If the execution environment exits, the main menu opens
in the device display.
The interactive console allows you to enter and execute Python commands.
Note: The current Python version for Series 60 does not include all the standard Python library
modules. Some extension modules that work in the phone are not implemented in the SDK version.
For more information on standard library modules, see Programming with Python for Series 60
Platform [2].
Note that in some Series 60 phone models the dictionary is on by default. This may cause difficulties
while using the interactive console. It is advisable to turn the dictionary off and also to specify
lowercase characters only as the case is significant in Python.
The Python interpreter prompts with ">>>". You can type some basic command like
and see the output on the screen (see Figure 5). Note that you can use the navigation key to produce
<enter>. It can also be produced by pressing the '0' ('zero') key three times.
When using an emulator, note that you cannot type quotation marks using a keyboard; they have to
be selected using the emulator’s own keys instead. However, you can press Enter in the keyboard.
Note also that sometimes the last line of text is not fully visible in the emulator’s display.
To end the interactive console, press the Exit key. You can also select Options > Previous command to
get any of the previous commands from the buffer for editing. Select Previous repeatedly until you
get the appropriate command.
The following example uses Python for Series 60 -specific extension module called appuifw and
shows how to write your own Python scripts. For information on the appuifw module, see Python for
Series 60 Platform API Reference [1].
# Hello
from appuifw import *
note(u"Hello World!", "info")
3. Save the file as hello.py (In an emulator, save it to the Script folder and skip the following
steps.)
4. Go to the location where you saved the file and right-click it.
5. Send the file to your phone. A message appears and asks you to save the file.
6. Save the file as a Python script.
If sending the file fails, check that you do not have a file with the same name already in the Inbox. If
this is the case, delete the earlier message.
Note: The default.py script defines where the execution environment looks for scripts and
modules in the new directory/directories. For more information on default.py, see Programming
with Python for Series 60 Platform [2].
Many standard Python modules and extensions work unmodified with Python for Series 60; for a list
of these, see Python for Series 60 Platform API Reference [1]. If you have Python 2.2 installed on a PC,
you can install the standard modules to the phone by copying them from the libs directory. You can
also experiment with unlisted modules. Some standard modules (e.g., random.py and Unicode
codecs) were left out in order not to waste storage space in the device.
For more information on extensions, see Table 2. For writing a Python script and writing your own
Python extensions, see Programming with Python for Series 60 Platform [2].
5 Python Installer
The Python Installer makes it possible for the users to install Python scripts and library modules to the
phone by sending them to the phone as such. Python Installer is installed simultaneously with Python
for Series 60, but it is not necessary when using an SDK.
The Python Installer comes with a MIME (Multipurpose Internet Mail Extensions) type recognizer. It
recognizes files with filename extensions .py, .pyc, .pyo and .pyd.
The Python Installer asks on installation whether the file is to be installed as a "Python script" (under
Python execution environment) or as a "Python lib module" (library component). Files with the
extension .pyc, .pyo or .pyd can only be installed as a library (see Table 2).
Table 2: Installation options
Python for Series 60 can use .pyc (pre-compiled) and .pyo (optimized) files created on other
platforms and moved to the phone. Using precompiled files can improve performance but the gain is
usually minimal. A .pyo file leaves out documentation and comments, so it can save space. The
phone itself does not save compiled or optimized files.
To remove Python for Series 60 from your PC, use the Add/Remove Programs feature in Control
Panel.
To remove .py, .pyc or .pyo files from your phone, open the filebrowser.py and select the file
you want to remove. You can use the navigation key to delete the file.
To remove SIS files, open the application manager and select Options > Remove.
8 References
1. Python for Series 60 Platform API Reference
http://www.forum.nokia.com/