Apps

Rust and Python for small tools

Python is often my quickest route from an idea to a working script. Suppose I want to read a file and print its non-empty lines with line numbers. The whole program can stay focused on the operation itself:

from pathlib import Path

for number, line in enumerate(Path("notes.txt").read_text().splitlines(), 1):
    if line.strip():
        print(f"{number}: {line}")

Rust asks me to be more explicit about reading the file and handling failure. That adds a little ceremony, but the result is a standalone binary with clear error propagation and no runtime environment to prepare:

use std::{fs, io};

fn main() -> io::Result<()> {
    let text = fs::read_to_string("notes.txt")?;

    for (index, line) in text.lines().enumerate() {
        if !line.trim().is_empty() {
            println!("{}: {line}", index + 1);
        }
    }

    Ok(())
}

For a disposable script, Python’s compactness is hard to beat. When a tool becomes something I depend on, distribute, or extend, Rust’s explicitness and single-binary deployment become more attractive. The useful question is not which language wins, but how long the tool is likely to live.