Poisonal
Pass it along a thing worth keeping

TramCité Rail System Deal Advances to Next Phase of Announcing Future Announcement

The Quebec City TramCité rail system project moved forward this week when the city council voted unanimously to authorize a planning committee to establish a timeline for announcing when the deal would be publicly disclosed. The vote came after eighteen months of negotiations between municipal officials and three separate infrastructure consulting firms, each of whom has recommended that further consultation be conducted before the deal's basic terms are made available. The current projected date for the first public announcement of the announcement timeline is December 2026, provided no new consulting phases emerge. A city spokesperson said the project remained on schedule and expressed optimism about its eventual realization, defined for purposes of this statement as the completion of all preliminary review stages.

4 months ago • 8 min read
Stand-up

the psychic weight of memory management

Bootcamp Graduates Confirm They Have Memorized Import Statement While Unsure of Algorithm

Bootcamp Graduates Confirm They Have Memorized Import Statement While Unsure of Algorithm

Questions

Python Gotchas: The FAQ No One Wanted to Ask

Why does `a is b` evaluate to true for 100 but false for 1000?
Small integers from -5 to 256 are preallocated in memory for optimization, making `is` comparisons return true unexpectedly. Python caches these values because they're frequently used, so two variables holding 100 will point to the same object in memory. Ask for 1000, and Python creates a fresh object each time—different identities, different `is` results. This has ruined more than a few production clusters at 3 AM when someone compared integers instead of using `==`.
Why does my list keep growing when I pass it to a function?
Default arguments are evaluated once, when the function is defined—not each time you call it. If you use a mutable default argument like `def append_item(item, items=[])`, that empty list persists across every call. Append to it in one invocation, and the list is still there, still full, when you call the function again. The fix: use `None` and create a fresh list inside the function. This trap has launched a thousand confused StackOverflow posts because the behavior feels intentional but reads like a bug.
Can I rely on dictionary order?
Yes—but only if you're running Python 3.7 or later. In earlier versions, dictionary insertion order was not guaranteed, and your keys could shuffle themselves for reasons that made no sense at the time. Modern Python treats dicts as ordered by design, though this wasn't always a feature you could count on. If you're maintaining code that touches Python 3.6 or older, assume your dictionaries might betray you.
Why is my variable undefined after the loop ends?
Unlike other languages, Python doesn't create a new scope for loops—the loop variable leaks out into the enclosing scope and stays there. After `for i in range(10):`, the variable `i` still exists in your local namespace with the value `9`. This is by design, not a bug, but it catches everyone trained in languages where loop variables vanish. It also means if you reuse a loop variable name carelessly, you'll overwrite whatever it held before.
Why does `None + 5` crash when I swear I checked for None?
You probably checked `if x:` instead of `if x is not None:`. An empty list, zero, an empty string, and an empty dict all evaluate to False in a boolean context, but only `None` is actually None. If your variable is `0` or `[]` and you skip it with a falsy check, you've created a silent bug. The safe move: use explicit identity comparison with `is None` or `is not None` when you mean to check for the absence of a value, not its falsiness.
Why does modifying a class variable affect all instances?
Class variables live on the class itself, not on individual instances. When you write `MyClass.shared = []` and then access it through `self.shared`, you're reading from the class if no instance variable shadows it. Append to that list through one instance, and every instance sees the change. This is technically correct but psychologically devastating. The lesson: initialize mutable defaults in `__init__`, not at the class level, unless you genuinely want shared state across all instances.
Why does my lambda function capture the wrong variable?
Lambda functions and nested functions capture variables by reference, not by value. Write `funcs = lambda x: i x for i in range(5)` and all five lambdas will use the final value of `i`—which is 4. By the time you call the function, the loop has finished, and `i` points to its last value. Fix it with a default argument: `lambda x, i=i: i x`. This quirk has confused every Python learner who expected closures to work like a snapshot.
Can I rely on the order of keyword arguments in **kwargs?
Yes, as of Python 3.7, keyword arguments maintain insertion order inside `kwargs`. Before that, the order was undefined and depended on hashing internals. If you're writing code for older Python versions, never assume `kwargs` will preserve the order in which arguments were passed. Modern Python treats it as an ordered mapping, so you can iterate predictably—but the old scars remain in production codebases that had to work around this.

The slip.

The slip.

More from Quebec City