Category: Python

Byte Insight

Python – Strings

A string is a list of characters and, in Python, they are easy to declare using speech marks.

myquote = “Talk is cheap. Show me the code.”

RPi Twitter Led

This program follows on from the standard Python Twitter experiments.

The original inspiration for this whole experiment came from a @Rob Bishop (OCR) Raspberry Pi Recipe Card.  The objective of the program is to light an LED every time a tweet containing a particular word is sent to a certain person.

Twitter

The original inspiration for this whole experiment came from a @Rob Bishop (OCR) Raspberry Pi Recipe Card  (ocr-recipe-card-twitter-led.pdf). The objective is to interact with Twitter using Python.

Python

Python is a highly readable language that is easy to use and learn hence it is gaining popularity as an education language.  However, this should not lead anyone to consider it a child’s language for it is not.  It is very powerful, flexible and platform independent.  It supports many styles of programming from scripting and web design to  GUI/Game development.

TKinter Drawing

TKinter is the easiest way to get drawing in Python.

Tkinter Events

Tkinter employs a type of programming called Event-Driven which means that the program runs in a endless loop waiting for things (events) to happen.  In order for the program to respond to these events it needs to know what to listen for.  

Time

It is not uncommon to use time (or dates) or programs in some way or another.   If you are writing games you might want to record how long something takes or give the player a restricted amount of time.  Thankfully Python has some pretty good libraries (datetime, time) to help you.

Turtle

Python Turtle is based on the Logo Programming Language that has been used as a popular way of teaching children programming for many years.  

File I/O

Many programs require that we store data between runs or load at start up.  A simple example might be highest scores for a game or questions for a quiz program. Often the data will need to be structured in some way to make it easier to load and common examples include: Comma Separated Values (CSV);  EXtensible Markup Language (XML); and JavaScript Object Notation (JSON). Python makes it very easy to open and work with files.   All examples in this guide assume that the file is located alongside the program file in the same folder.

Arrays & Lists

Python provides a number of array like structures that you can use.  Python Lists are probably more flexible and the easiest to use.  They are able to contain data of different types and can grow/shrink in size easily.   However, the Array datatype takes up less space but is of fixed size and single data type.  Python also provides Dictionaries, which let us store values linked to a specific key.   There are other data structures available but they are beyond the scope of this page.