Reference library
Automation & scripting
CLI tools, scheduled jobs, filesystem tasks, and glue scripts that save time.
How to Generate a QR Code in Python
Generate a QR code image from a URL string using the qrcode library and save it as a PNG file.
import qrcode
# Data to encode
data = "https://www.example.com"
# Create QR code instance
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
# Add data to QR code
qr.add_data(data)
qr.make(fit=True)
# Create an image from the QR code
img = qr.…
How to Resize Hundreds of Images in Batch with Python
Resize every image in a folder to a target size using Pillow, creating a new subfolder for processed files.
import os
from PIL import Image
def resize_images_in_batch(directory, output_size=(800, 600)):
if not os.path.exists(directory):
print(f"Directory {directory} does not exist.")
return
output_dir = os.path.join(directory, "resized")
os.makedirs(output_dir, exist_ok=True)
for filename in…
Browse by section
Each section groups closely related Python snippets.
Automation & scripting — Python code examples
What you will find here
This page collects automation & scripting snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.
Samples vs tutorials and challenges
Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.