Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
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)

Product type Book
Published in Sep 2015
Publisher
ISBN-13 9781783551590
Pages 200 pages
Edition 1st Edition
Languages
Author (1):
Dan Nixon Dan Nixon
Profile icon Dan Nixon

Using packages in your Python code


We will first have a look at the ways in which third party code and libraries can be downloaded, installed, and included in the Python scripts and application we write.

Importing modules

As we have already seen in several of the examples used so far, Python libraries (modules) are used in code by importing them using the import statement. However, so far, we have only been importing the entire modules. For example, import threading imports the entire threading module and to use, say, the Thread class, you would have to specify it as threading.Thread.

Python also allows you to import single classes, and even functions, using a slightly modified syntax, as shown next:

from threading import Thread
from time import time

This preceding code imports just the Thread class and the time function from the threading and time modules respectively. Now when you want to use either within the rest of the file, you would only need to specify either Thread or time, rather than...

lock icon The rest of the chapter is locked
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 $15.99/month. Cancel anytime}