Learn Python with our free tutorials

If you're a beginner who wants to learn Python programming, you've come to the right place. If you're a more advanced coder who wants to push their skills even further, we've got your covered there too. Below you'll find our list of code projects for Python: tutorials that help you learn Python without boring you to death with hello world nonsense - we want to help you learn how to Make Cool Things, and you'll learn along the way.

We'll be adding more tutorials as time goes by, but for now just jump in - pick a tutorial from the list below and have some fun!

(PS: if you're looking for all our coding tutorials regardless of language, visit our programming tutorials section)


Code Project: build a PyGTK language translator

Code

Once you understand the basics of PyGTK, you can make some neat apps just by drawing upon some of the incredible APIs that are available from well-known companies such as Facebook, Twitter and Yahoo. In this video tutorial you'll learn how to work with Google's Translate API, which can translate a huge range of languages on the fly, then back up your knowledge with a simple PyGTK user interface that puts a pretty face on it all.

Code Project: build a PyGTK RSS reader

Code

As we saw in part one of this video series, Python makes it easy to create GTK apps. Well, it turns out that Python also makes it easy to read XML from the web, which means we can make something like an RSS reader in no time at all. In this video tutorial you'll learn how to work with XML, using RSS as an example, while also learning how GTK handles data in multi-line text fields and combo boxes.

This tutorial is dedicated to Evan, who donated at least $50 to support free software - if you want to see more video tutorials like this one, all you have to do is donate to support the Libre Graphics Meeting. Easy!

Python + PyGTK + WebKit in 20 minutes

Code

In season 2 episode 7 of our podcast we laid down the simple challenge for each of the four podcasters - Andrew, Graham, Paul and Mike - to produce something original for the website. Paul - eager to show the world how much he, er, loves Python - has now finished his entry, and you'll find it below: a video talking you through how to get started with Python, PyGTK and WebKit. It's easier than you think!

Code Project: create an animated RSS reader with Clutter

Code

In a previous tutorial we had a look at the basics of Clutter as we used it to build a network speed monitor. This time we'll be looking at some of the very powerful animation techniques used in Clutter, how to group objects, and a little more about text actors. We will be doing this in the guise of implementing a feed reader. There isn't enough space for us to implement a complete multi-stream reader and explore the animations, but we will be covering enough ground to get you started on building such a beast, including fetching the data from the feed and applying it to the Clutter objects.

For those of you who haven't been tempted by one of these magnificent Python tutorials before, we usually try to do as much as possible in the interactive mode of Python first. It is a kinder, gentler environment than the normal mode in which programs are run, as you can type things in and experiment. The code listings in these cases include the Python prompt >>> at the beginning of the line when you have something to type in, and without it when the environment is giving you some feedback, just as it appears on screen.

(NB: don't miss our collection of free Python tutorials, and you can also try your hand at our Clutter beginners tutorial for C programmers if you're feeling adventurous!)

Code Project: monitor /proc with Python and Clutter

Code

If you already read our beginner's guide to the Clutter toolkit and wished it were available in something other than C, then good news: we're putting together a tutorial series covering PyClutter, the Python binding to Clutter, which merges all the power and beauty of the Clutter toolkit with the simplicity and brevity of Python.

So, let's start with a simple project to get things going: you're going to produce a network monitor that monitors data transfer and displays it all on the screen using Clutter. It's nice and easy, but we're going to be adding more involved PyClutter tutorials in the coming months, so you should get started while the learning curve is shallow!

Code Project: upload pictures to Flickr with Python

Code

Python is a great way to make apps quickly, and what better source of data is there than the world wide web? We've already shown you how to control Digg with Python and how to create a Twitter bot in Python, and now we turn our beady eyes towards Flickr, the home of more cat photos than I Can Haz Cheezburger knows what to do with. If you want to try your hand at uploading photos to Flickr, while learning just a smidge of PyGTK along the way, this project is for you.

If you're desperate for even more things to code, don't forget our complete code projects archive is waiting for you...

Code Project: control Digg with Python

Code

Everyone knows that Digg is a hugely popular social news website where like-minded folks gather and flame each other to death. But if you're a Digg user and want to flex your coding skills to get a little more from the site, we've got the perfect code project for you: we're going to show you how to write a Python app to read Digg submissions and geo-locate them using GeoIP.

You should know that, even though there's a perfectly reasonable - if slightly out of date - API for Digg, we're going to create our own miniature one instead that does just what we need. If you want to go further you'll find this an easy place to start, and it also gives you some good practice in working with XML.

Make a Python game in minutes with Gloss

Code

When Hudzilla isn't busy working on his free Mono tutorials using C#, he likes to hack on one of his pet Python projects: Gloss. It's hosted right here on TuxRadar and you may already have given it a try. If not, he wrote a short tutorial for PC Plus magazine a few months ago, and took the time to repurpose it for the web.

So, if you fancy learning the fastest way to create Python games, read on as Hudzilla talks you through an example Gloss project...

Code project: create a Python Twitter bot

Code

Once upon a time, there was a person who decided that people needed more distractions in their lives, so he created Twitter. This may not be exactly how they tell the story at Twitter HQ, but that's probably because it would create a less than glamorous image (oh, and it's also wildly inaccurate). After all, Twitter is pretty much constantly in the news. If you want to catch up with where in the world Stephen Fry is now, what everybody in North America had for lunch or precisely how smugly great Jonathan Ross thinks he is today, there's really only one place to turn.

Amazingly, Twitter can be put to useful things as well. As it happens, Twitter's application programming interface (API) is particularly convoluted - it seems to have evolved by using many different ways of doing various things. That needn't worry us, though, because there are plenty of API wrappers for Python. The one that's most suited for us is the standard Python-Twitter, which is available through most repositories and also at http://code.google.com/p/python-twitter.

Code Project: Tower of Hanoi in Python

Code

If you've already followed our previous code projects and are using the weather for wallpaper, enjoying talking RSS feeds, running your own Ruby-powered web server and chatting to your own IRC bot, here's something new to try: we're going to show you how to make a Tower of Hanoi game using Python.

Code Project: Use weather for wallpapers

Code

Not all information on the web is static, connected in a meaningful way, or even as cool as it should be. Which is why one of the post-web 2.0 movements of note is the mashup - the repurposing of data from the web into new and exciting forms. Welcome to the world of data punk.

Code Project: Build an Ncurses UI with Python

Code

Picture the scene: you're logged into a remote server via SSH, or you've installed a new graphics card and you're left staring at the command line. You need to enter a command, but you can't remember the zillion options that go along with it. You're stuck - all you can do is consult the manual pages and pore through pages of waffling technical gobbledygook. We've all been there, and no matter how experienced you are with Linux, sometimes you need to accomplish a job quickly without sifting through masses of reading material.

In this coding project, we're going to solve this problem - and have fun along the way! We'll show you how to write a dialog-based program that gives you options one-by-one so that you don't need to consult the man pages. In this guide, we'll show you how to write a nifty front-end for the useradd utility, a command which (unsurprisingly) lets you add user accounts to your Linux installation. Like many administration tools, useradd requires a long string of options and parameters; we're going to make it much simpler by creating an interactive dialog-driven version called UserMaster.

Code Project: Make talking RSS feeds

Code

On the face of it, writing a script/program to download and parse an RSS feed, and from there send news items to a speech synthesizer, sounds ambitious - even for TuxRadar. But as it turns out, it's actually rather straightforward.

Principally, this is thanks to three technologies, Python, Festival and Linux. Python, the world-dominating scripting language par-excellence makes it easy to construct a script without too much thought or effort. The open source Festival Speech Synthesis System sounds fantastic, and can be installed with just a couple of clicks from your distribution's package manager. And Linux itself; without its powerful pipes and process scheduling, we'd have to spend a lot more time writing that functionality into our program, and we'd also need to add a GUI to make it all easily accessible.

Luckily, all we need to do is write a small Python script and use a little command line magic to tie all these things together. We're going to write a simple script in Python that will output plain text news stories than can then be piped into Festival, which will then speak the news through your speaker or headphones. This gives you maximum flexibility. This two-pronged approach (Python script piped to Festival) can be modified to suit almost any purpose. In less than an hour, you'll be able to sit back and listen to the dulcet tones of a female voice synthesizer reading the latest happenings from TuxRadar.com.

Code Project: Build a mouse game with Python

Code

Most modern games take thousands of man-hours to create, not to mention an army of artists and musicians, but there's still some scope for solitary hacker to write something entertaining. After all, it didn't take a team of 500 coders and a Hollywood movie-set budget to create Tetris - Alexey Pajitnov managed pretty well on his own (until various filthy capitalist running-dogs of the West ran off with his idea, of course...)

In this tutorial, you're going to learn how to make a really simple mouse game with Python. If this is the first coding tutorial you've read - and you've certainly never written a line of Python code before - you'll be pleasantly surprised by how easy it is to understand; Python code is famous throughout the programming world for being very much self-explanatory.

Code Project: Build a flash card app

Code

In this coding project, we're going to create a flash card program to help you remember foreign words. It displays an English word and asks you to choose its German equivalent from a list of three randomly chosen options, keeping a score as you progress.

But it's not just limited to German – you'll be able to use it for any language, or indeed for anything else you want to learn! You could even set it up to display the name of an animal, having the program test you on its species.

Code Project: Build a Space Invaders clone

Code

Programming is great. You get to create something new, stimulate your brain and have fun along the way - especially if you're programming games. So we're going to show you how to write your very own Space Invaders lookalike called PyInvaders - but don't panic if you're tired of dull programming theory: take that palm away from your forehead. Here we'll focus on doing Cool Stuff(tm), making a game work instead of warbling about algorithms, data structures and object oriented polymorphism encapsulation. Or whatever.

Consequently, to follow this guide it helps if you have some prior programming experience. We're not going to explain everything in depth; if you've dabbled in some code before, and know your arrays from your elbow, you won't have any problems. For those completely new to programming, you might find some of the terminology a bit bamboozling, but you don't have to understand it all. Just take in what you can, grab the source code from the DVD and start experimenting by making changes yourself. That's how all great programmers got started!

So, as mentioned, we'll be making a mini Space Invaders clone. Our choice of programming language is Python due to its simple syntax and code cleanliness - it's very easy to read. PyGame, a language binding that wraps the SDL multi-media library around Python, will provide the graphical plumbing for our program, saving us from the chore of manipulating images by hand. Most distros have Python pre-installed, and PyGame is available in nigh-on every repository, so get the tools, open up a text editor, and let's get cracking...

Username:   Password:
Create Account | About TuxRadar