Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications)

You're reading from   Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications) Learn to design and implement reliable Python applications on the Raspberry Pi using a range of external libraries, the Raspberry Pis GPIO port, and the camera module

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781783551590
Length 200 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Dan Nixon Dan Nixon
Author Profile Icon Dan Nixon
Dan Nixon
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Your First Steps with Python on the Pi FREE CHAPTER 2. Understanding Control Flow and Data Types 3. Working with Data Structures and I/O 4. Understanding Object-oriented Programming and Threading 5. Packaging Code with setuptools 6. Accessing the GPIO Pins 7. Using the Camera Module 8. Extracting Data from the Internet 9. Creating Command-line Interfaces 10. Debugging Applications with PDB and Log Files 11. Designing Your GUI with Qt Index

The Python development tools

Now that the Pi is set up and running Raspbian, we can have a look at some of the tools we will use to develop Python scripts (small text files containing commands) and applications. Most of the time we will be using either the interactive Python terminal to execute the code line by line or the python executable to run full scripts and applications.

We will first look at the interactive terminal. First open a terminal by clicking on the black monitor icon in the top right corner of the desktop. This will open an LXTerminal window. In this window, type python and press Enter. This will start the interactive terminal as shown in the following screenshot:

The Python development tools

From here we can type the Python code line by line; each line is executed as soon as it is typed, making this tool useful for quick testing and debugging (I also find that it makes a nice command line calculator). To demonstrate this, type in the following code and press Enter:

print "Hello, world!"

This will print the test Hello, world! on the line next to where you typed it in, as shown in the following screenshot:

The Python development tools

The python executable can also be used to run the existing Python script files (which have the .py file extension), which we will look at later in the chapter.

One alternative to the interactive terminal is the IDLE Integrated Development Environment (IDE) which can be used both as an interactive terminal and a source file editor, and provides syntax highlighting for the Python files. It can be found by selecting Python 2 from the Programming submenu of the main menu on Raspbian, as shown in the following screenshot:

The Python development tools

When first opened, it will be in the interactive terminal mode and can be used in the same way as the terminal ran from the command line, as shown in the following screenshot:

The Python development tools

Python 2 versus Python 3

You will notice that there are two versions of Python installed by default on Raspbian: Python 2.7 and Python 3.1. Whilst the fundamentals of Python programming have not greatly changed between the two versions, there are notable differences that may prevent a code that was written for one version from working when executed with the interpreter for a different version.

For this reason, we will only use Python 2.7 in this book as this has the widest library support and is still the default Python version on many operating systems.

Note

More information of the differences between Python versions is available on the Python Wiki at wiki.python.org/moin/Python2orPython3

You have been reading a chapter from
Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications)
Published in: Sep 2015
Publisher:
ISBN-13: 9781783551590
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime