XIO

xWire

Posts from every feed QUEST has found across the web — blogs, news, podcasts, channels and more.

AskPython

Python Tutorials for Beginners and Experienced Programmers

Python String Functions: Methods by Task

Text in a program may need a small change or check before you use it. Python string methods are operations you call on text to trim its edges or split it into parts. I’ll show how to choose a method by the result you need and how to use common methods in a short text-cleaning […]

Filter Function in Python

When a list of records includes entries that pass a condition and entries that do not, selecting the matches calls for a test. Python’s filter() applies a test, called a predicate, to each item and returns an iterator containing the items that pass. I’ll show how to write that test and consume the iterator, then […]

Python Relative Imports: What the Dot Means

As you split a Python project into packages, you may see a leading dot in an import and wonder which module it names. Python relative imports use those dots to resolve a name from the importing module’s package. I’ll explain how each dot changes the starting point and show how to run a package module. […]

Python type() Function: Check and Create Types

An unfamiliar Python value can leave you unsure what operations it supports. type() reports the value’s class, which defines what its instances can do, or creates a class when called with three arguments. I’ll walk through both forms of type() and show when to use type() or isinstance(). TL;DR: What Python type() Does Python type() […]

Args and Kwargs in Python

As a function grows, callers may need to supply values beyond its named parameters. In Python, *args collects extra positional arguments into a tuple, while **kwargs collects extra keyword arguments into a dictionary. This article explains how to collect and expand those arguments, then how to forward them through another function. TL;DR: *args and **kwargs […]

Creating Python Modules

When one Python file needs to use a function defined in another, you can put that function in a module. A Python module is a source file that another file can import. In this piece, I’ll show how to save reusable code in a .py file and import it from another script. TL;DR A Python […]

Python Modules: Create and Import Them

To reuse a function across Python files, you can put it in one file and import that file where you need it. A Python module is a file of statements and definitions, usually with a .py extension, that another file can access with an import. I’ll show how to create and import a module, then […]

Catch Multiple Exceptions in Python: Handle Errors

When a calculation uses text as a number, the conversion or the division can fail. Python’s except clauses let a program catch errors raised inside a try block and choose how to respond. This article shows how to handle several exception types with one clause when they share a response, and how to use separate […]

Create a Range of Dates in Python

Calendar-based tasks often need every day between a start date and an end date. Python’s date and timedelta classes let you move forward one day at a time to build that sequence. I’ll show how to create a range that includes the end date, then explain when to stream the dates or store them. TL;DR: […]

Python Datetime Module: Work with Dates and Times

Python code that calculates with calendar dates or clock times can keep those values as objects until it needs display text. The built-in datetime module provides the types and operations for that work. In this piece, I’ll show you how to create date and time values, then handle local clock changes with a named time […]

Create a Directory in Python with pathlib

When a script saves a file inside a new folder, that folder has to exist first. Python’s standard library provides pathlib for working with paths, and Path.mkdir() creates a folder while parents=True tells it to create any missing folders above it. I’ll show how to create a directory and check where a path written from […]

Environment Variables in Python: Read and Set

A Python application can use different settings in development and deployment without changing its source code. Environment variables carry those settings into a program when it starts, and Python lets your code read or change them. I’ll show you how to choose what happens when a setting is missing and how to read or set […]

Copy a File in Python with shutil

A CSV file may need a second copy in another directory while the original stays available. Python’s shutil module provides file-copy functions, and shutil.copy() writes the file at the destination while leaving the source in place. I’ll show you how to copy a file with shutil.copy() and read the output to see that the source […]

Double Iteration in Python List Comprehensions

When values from two iterables need to go into one Python list, the order of the loops determines the order of the results. A list comprehension builds a new list by evaluating an expression for the values its clauses supply. I’ll explain how the clauses map to nested loops and show how the expression controls […]

List Comprehension in Python: A Guide

A loop that builds a list from changed input values can leave you wondering whether there is a more direct way to write it. A Python list comprehension builds a new list by applying an expression to items from an iterable, with an optional filter. I’ll show how to turn that loop into a comprehension […]