Writing Your First Python Django Application

Create A Django Project The previous article Introduction to Python’s Django presented an overview of the Django Framework. In this article, we are going to write a simple Django application from scratch. The first step is to create a project using one of Django’s built-in commands django-admin.py. In a Virtualenv, type this command: [shell] django-admin.py […]

Read More

Lambda Function Syntax (Inline Functions) in Python

Python’s syntax is relatively convenient and easy to work with, but aside from the basic structure of the language Python is also sprinkled with small syntax structures that make certain tasks especially convenient. The lambda keyword/function construct is one of these, where the creators call it “syntactical candy”. Here we’ll examine how to use them. To understand the lambda keyword/function and their […]

Read More

Catching Python Exceptions – The try/except/else keywords

Often times when coding a python masterpiece, there are certain things that could go wrong when executing your masterfully designed code. Things such as files or directories that are missing, empty strings, variables that are supposed to be strings but are actually arrays at run-time. These things are called exceptions in Python. This is what […]

Read More

PySide/PyQT Tutorial: QListView and QStandardItemModel

In our last instalment, we discussed Qt’s QListWidget class, which allows the user to make simple single-column list boxes. For more advanced list controls, however, a more flexible widget is required; for that reason, Qt supplies the QListView widget, which allows more varied items to be created. It is a pure presentation widget, which displays […]

Read More

Cutting and Slicing Strings in Python

Python Strings as Sequences of Characters Python strings are sequences of individual characters, and share their basic methods of access with those other Python sequences – lists and tuples. The simplest way of extracting single characters from strings (and individual members from any sequence) is to unpack them into corresponding variables. [python] >>> s = […]

Read More

PySide/PyQt Tutorial: Using Built-In Signals and Slots

In the last installment, we learned how to create and set up interactive widgets, as well as how to arrange them into simple and complex layouts using two different methods. Today, we’re going to discuss the Python/Qt way of allowing your application to respond to user-triggered events: signals and slots. When a user takes an […]

Read More

PySide/PyQt Tutorial: Interactive Widgets and Layout Containers

In the last installment, we looked at some of the functionality provided to all QWidget-descended Qt widgets, and we looked at one specific widget, the QLabel, in more depth. We also worked our way up to an example that illustrated the structure of a simple Python/Qt application. Thus far, however, we’re not able to do […]

Read More

Intro to PySide/PyQt: Basic Widgets and Hello, World!

This installment gives a introduction to the very most basic points of PySide and PyQt. We’ll talk a bit about the kinds of objects they use, and talk through a couple of very simple examples that will give you a basic idea of how Python/Qt applications are constructed. First, a basic overview of Qt objects. […]

Read More

Python Decorators Overview

Decorators in Python seem complicated, but they’re very simple. You’ve probably seen them; they’re the odd bits before a function definition that begin with ‘@’, e.g.: [python] def decorator(fn): def inner(n): return fn(n) + 1 return inner @decorator def f(n): return n + 1 [/python] Note the function called decorator; it takes a function as […]

Read More

Introduction to Python Classes (Part 2 of 2)

In the first part of this series, we looked at the basics of using classes in Python. Now we’ll take a look at some more advanced topics. Python Class Inheritance Python classes support inheritance, which lets us take a class definition and extend it. Let’s create a new class that inherits (or derives) from the […]

Read More