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

List Comprehension in Python

Sometimes we need to generate lists which follow some natural logic, such as iterating over a sequence and applying some conditions in them. We can use Python’s “list comprehension” technique to write compact codes to generate lists. We can loop through a sequence, and apply logical expression. First, let’s look at a special function range […]

Read More

Using the Python Tempfile Module

While programming in Python, there will likely be times where you have some data that needs to be utilized or manipulated in the form of a file but hasn’t yet been written to one. Naturally, the first solution that comes to mind is to open a new or existing file, write the data and finally […]

Read More

Introduction to Python Classes (Part 1 of 2)

Classes are a way of grouping related bits of information together into a single unit (also known as an object), along with functions that can be called to manipulate that object (also known as methods). For example, if you want to track information about a person, you might want to record their name, address and […]

Read More

Reading and Writing to Files in Python

Manipulating files is an essential aspect of scripting in Python, and luckily for us, the process isn’t complicated. The built-in open function is the preferred method for reading files of any type, and probably all you’ll ever need to use. Let’s first demonstrate how to use this method on a simple text file. For clarity, […]

Read More