December 2026
Every post published in December 2026, newest first. Pick a day to jump straight to it.
- Posts
- 410
- Topics
- 77
- Reading time
- 40 h
- Active days
- 3
Posts 271–300 of 410 · December 2, 2026
Page 10 of 14
Wednesday, December 2, 2026
30 of 81 posts
How to Write a Comment in Python
Leave a note in Python code with a # comment, on a line of its own or after the code, and see that # inside quotes is plain text. Real output from Python 3.15.2, plus the SyntaxError that // gives and how to switch off several lines.
3 min readHow to Check Whether Either of Two Conditions Is True in Python with or
Run code when at least one of two conditions holds with Python's or, and use its left-to-right, stop-early checking to guard a risky test, such as is None before len(). Real output from Python 3.15.2, including the TypeError when the order is wrong.
4 min readHow to Check Whether a Value Is None in Python with is None
Test for Python's None with is None and is not None, the way PEP 8 asks, and see why if not value is a different test that also treats 0, empty text and empty lists as missing. Real output from Python 3.15.2.
5 min readHow to Put a Line Break in a Python String with \n (Newline)
Start a new line inside a Python string with the \n escape sequence, and leave an empty line with \n\n. Real output from Python 3.15.2, plus why /n prints as typed and how a raw string keeps \n as two characters.
4 min readHow to Stop a Python Command-Line Tool with a Usage Error Using argparse error()
Check command-line values that argparse can't check on its own, such as two options that depend on each other, and stop with argparse's own usage message and exit status 2 by calling parser.error(). Real output from Python 3.15.2 in zsh and PowerShell.
5 min readHow to Limit a Command-Line Option to Certain Values in Python with argparse choices
Accept only a fixed list of values for a command-line option with argparse's choices argument: the allowed values appear in the help, and anything else stops with an error and exit status 2. Real output from Python 3.15.2, including its new 'maybe you meant' suggestion.
5 min readHow to Pass a Function as an Argument in Python
Hand a Python function to another function by writing its name without parentheses, and let the other function call it. Real output from Python 3.15.2, plus the TypeError you get when you add the parentheses.
4 min readHow to Define a Dictionary's Keys and Types with TypedDict in Python
List the keys a Python dictionary should have, and the type of each value, with typing.TypedDict. Real output from Python 3.15.2, plus why Python doesn't reject a wrong type when the code runs, and why book.title fails.
4 min readTensorFlow Tutorial for Deep Learning in Python — Part 1: Install TensorFlow and Set Up Your First Project
Start a deep-learning project in Python: what TensorFlow and Keras are, install TensorFlow 2.22 with uv on Python 3.14, check its version and devices, measure its slow first import, and download 3,670 flower photos with a checked SHA-256.
34 min readFixed: "all versions of tensorflow have no wheels with a matching Python version tag (e.g., cp315)"
On Python 3.15, uv add tensorflow failed because TensorFlow 2.22.0 publishes wheels for Python 3.10 to 3.14 only. Changing requires-python to >=3.14 and pinning Python 3.14 with uv python pin fixes it.
7 min readFixed: LangChain draw_mermaid() Diagram Labels Unreadable in Dark Mode
A LangChain agent drawn with get_graph().draw_mermaid() had nearly invisible labels in dark mode: the Mermaid text colours the boxes light and leaves the text to the theme, which draws it light. A NodeStyles with a dark text colour and a white start box fixed it.
12 min readHow to Find Slow Imports in Python with -X importtime
See how long every import takes with Python's -X importtime option: read the self and cumulative columns, save the report to a file, and sort it to find the slowest modules. Real output from Python 3.15.2, in bash and PowerShell.
7 min readHow to Make Python Packages Import Faster the First Time with uv --compile-bytecode
Make the first import of a package in a new environment as fast as the second by compiling its bytecode at install time with uv sync --compile-bytecode, then make it a project default with compile-bytecode = true. Real timings with uv 0.13.10 and Python 3.15.2.
8 min readHow to Measure How Long Python Code Takes with time.perf_counter
Time a piece of Python code with time.perf_counter: read the clock before and after, subtract, and print the seconds. Real output from Python 3.15.2, plus perf_counter_ns for whole nanoseconds.
4 min readHow to Set the Keras Backend with KERAS_BACKEND
Check which backend Keras 3 runs on with keras.config.backend, switch it to JAX for one command or inside a script with the KERAS_BACKEND environment variable, and see where the default lives in keras.json. Real output from Keras 3.15.1.
7 min readHow to Download and Extract a Dataset with keras.utils.get_file
Download a dataset archive once and reuse it from the cache with keras.utils.get_file: extract it, pin its SHA-256 hash, name its folder with fname, and keep it inside your project with cache_dir. Real output from Keras 3.15.1.
10 min readHow to Check Whether TensorFlow Can Use a GPU
Check whether TensorFlow sees a GPU with tf.config.list_physical_devices, list every device it can use, and read whether your TensorFlow package was built with CUDA from tf.sysconfig.get_build_info. Real output from TensorFlow 2.22.0 on a Mac.
4 min readHow to Check Which Version of TensorFlow Is Installed
Check which TensorFlow version a project uses with tf.__version__, read the build details in tf.version, and check it without importing TensorFlow with uv pip show. Real output from TensorFlow 2.22.0.
4 min readHow to Install TensorFlow with uv
Install TensorFlow 2.22.0 and Keras 3.15.1 into a uv project on Python 3.14, check the installed version, and run TensorFlow's own one-line check. Real output on macOS, plus the GPU routes for Linux and Windows.
6 min readHow to Get a File's Name from a Path in Python with Path.name
Get the last part of a path, the file or folder name, with pathlib's Path.name, see how it handles a trailing slash where str.split doesn't, and get the name without its extension with Path.stem. Real output from Python 3.15.2.
3 min readHow to Add a Type Hint for a Dictionary in Python
Write a type hint for a Python dictionary with dict[key type, value type], on a variable and on a function's parameter and return value, and see that Python itself doesn't enforce it. Real output from Python 3.15.2.
4 min readHow to Add a Thousands Separator to a Number in a Python f-string
Print big numbers readably in a Python f-string: a comma every three digits with :, an underscore with :_, decimals with :,.2f, and why a number stored as text can't take a separator. Real output from Python 3.15.2.
3 min readHow to Read a Command-Line Argument as a Path in Python with argparse type=Path
Make argparse hand your Python code a pathlib Path instead of a string by passing type=Path to add_argument(), so you can call .name, .suffix and .exists() on the argument straight away. Real output from Python 3.15.2.
4 min readHow to Add Subcommands to a Python Command-Line Tool with argparse
Give a Python command-line tool several commands, like git commit and git status, with argparse's add_subparsers(): one parser per command, its own arguments and help, and an error when no command is given. Real output from Python 3.15.2.
5 min readHow to Get the Absolute Path of a File in Python with Path.resolve()
Turn a relative path into a full, absolute one with pathlib's Path.resolve(), see it remove .. from a path, and learn why ~ needs expanduser() first. Real output from Python 3.15.2.
4 min readHow to Check Whether a Value Is in a Collection in Python with in
Check whether a value is in a set, a list, a string or a dictionary with Python's in operator, and its opposite not in, and see why in on a dictionary looks only at the keys. Real output from Python 3.15.2.
4 min readHow to Create a Set in Python
Create a Python set with curly braces or set(), watch it drop a duplicate, add an item with add(), and avoid the two traps: {} makes a dictionary, and a list can't go into a set. Real output from Python 3.15.2.
4 min readHow to Get a File's Extension in Python with Path.suffix
Get a file's extension in Python with pathlib's Path.suffix, see what it returns for capital letters, double extensions like .tar.gz and files with no extension, and get every extension with Path.suffixes. Real output from Python 3.15.2.
3 min readHow to List the Files in a Folder in Python with Path.iterdir()
List everything in a folder with pathlib's Path.iterdir(), put the entries in a fixed order with sorted(), keep only the files, and read the error you get for a folder that doesn't exist. Real output from Python 3.15.2.
4 min readHow to Sort a List in Python with sorted()
Sort a list in Python with the built-in sorted(): alphabetically, in reverse with reverse=True, and without caring about capital letters with key=str.lower, while the original list stays as it was. Real output from Python 3.15.2.
4 min read