RasPi 28 - 2016 UK.pdf

(6648 KB) Pobierz
Get hands-on with your Raspberry Pi
ESIGN
D
UILD
B
CODE
28
PYTHON
IN C
EMBED
+
PYTHON
Plus
Control lights with your Pi
DEVELOP WITH
Welcome
Just how much can you do with
a Raspberry Pi? I’m not sure we’ll
ever find out, because people
are producing amazing new
projects all the time that use the Pi in new and
different ways. Take the Pixel Globe project in
this issue, then compare it to the tutorial on
controlling lights, or the second part of our
guide to coding a videogame in FUZE Basic.
These projects couldn’t be more different, but
they all have the Pi at their heart.
One of the things that makes this possible
is Python, the ultra-powerful programming
language that we take an in-depth look at
this issue. With Python, you can ask the Pi to
do almost anything – the only real limit is your
imagination! Check out our guide for more.
Get inspired
Discover the RasPi
community’s best projects
Expert advice
Got a question? Get in touch
and we’ll give you a hand
Easy-to-follow
guides
Learn to make and code
gadgets with Raspberry Pi
Editor
From the makers of
Join the conversation at…
www.twitter.com/linuxusermag
@linuxusermag
https://www.facebook.com/LinuxUserUK
Linux User & Developer
RasPi@imagine-publishing.co.uk
RasPi@imagine-publishing.co.uk
Contents
Develop with Python
Learn how to speak the Pi’s language
Pixel Globe
Check out this futuristic hologram-style display
Control lights with your Pi
Who needs expensive IoT devices?
Code a Tempest clone in FUZE BASIC Part 2
Continue remaking a classic game in FUZE BASIC
Embed Python in C
Get the best of both programming worlds
Talking Pi
Your questions answered and your opinions shared
Develop With Python
Python is relied upon by web developers, academic
researchers and engineers across the world. Here’s how
to put your Python skills to professional use
System Administration
Get the most out of Python in handling all of the
day-to-day upkeep that keeps your system healthy
System administration tasks are some of the most
annoying things that you need to deal with when you
have to maintain your own system. Because of this,
system administrators have constantly been trying to find ways to
automate these types of tasks to maximise their time. They started
with basic shell scripts, and then moved on to various scripting
languages. For a long time, Perl had been the language of
choice for developing these types of maintenance tools. However,
Python is now growing in popularity as the language to use. It has
reached the point where most Linux distributions have a Python
interpreter included in order to run system scripts, so you shouldn’t
have any excuse for not writing your own scripts.
Because you will be doing a lot system level work, you will
have most need of a couple of key Python modules. The first
module is “os”. This module provides the bulk of the interfaces
to interacting with the underlying system. The usual first step
is to look at the environment your script is running in to see
what information might exist there to help guide your script. The
following code gives you a mapping object where you can
interact with the environment variables active right now:
THE PROJECT
ESSENTIALS
Pygame Zero
http://pygame-zero.
readthedocs.org
Pygame
http://pygame.org
Pip
https://pip.pypa.io/en/
stable/
Python 3.2 or later
https://www.python.
org
import os
os.environ
Zgłoś jeśli naruszono regulamin