Book Image

Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications)

By : Nixon
Book Image

Getting Started with Python and Raspberry Pi (Redirected from Learning Python By Developing Raspberry Pi Applications)

By: Nixon

Overview of this book

The Raspberry Pi is one of the smallest and most affordable single board computers that has taken over the world of hobby electronics and programming, and the Python programming language makes this the perfect platform to start coding with. The book will start with a brief introduction to Raspberry Pi and Python. We will direct you to the official documentation that helps you set up your Raspberry Pi with the necessary equipment such as the monitor, keyboard, mouse, power supply, and so on. It will then dive right into the basics of Python programming. Later, it will focus on other Python tasks, for instance, interfacing with hardware, GUI programming, and more. Once you get well versed with the basic programming, the book will then teach you to develop Python/Raspberry Pi applications. By the end of this book, you will be able to develop Raspberry Pi applications with Python and will have good understanding of Python programming for Raspberry Pi.
Table of Contents (13 chapters)
12
Index

Input/output

We will now take a look at some of the ways we can access the files and directories on the filesystem and create, modify, and read the files. Here we will look at using Python's file objects which are documented in full at https://docs.python.org/2/library/stdtypes.html#bltin-file-objects.

While this will suffice for simple files, there is a good selection of free libraries available online that take a lot of work out of creating and parsing the more complex files such as XML, JSON, and MIDI.

The os.path module

The os.path module contains various functions for performing manipulation of path names specific to the host operating system. This goes hand in hand with the file objects for accessing the files and directories on the filesystem, and helps to ensure that code can be used on any platform by handing all of the platform dependent and specific tasks for you (for example, the differences in file paths on Windows and Linux).

The following example demonstrates the most commonly...