Raymond Hettinger (@raymondh) 's Twitter Profile
Raymond Hettinger

@raymondh

Chief trainer for Mutable Minds.
Certified Public Accountant, Retired
Python guru. Alloy & TLA⁺ enthusiast.
Aspiring pianist. Former pilot.
Born at 320 ppm CO₂.

ID: 14159138

linkhttps://rhettinger.wordpress.com calendar_today16-03-2008 20:12:52

6,6K Tweet

75,75K Followers

543 Following

Raymond Hettinger (@raymondh) 's Twitter Profile Photo

#Python tip: Dunder methods aren't just for classes. People often forget that __getattr__ and __dir__ can be defined at the module level. This gives modules dynamic capabilities like lazy loading or context sensitive loads.

Raymond Hettinger (@raymondh) 's Twitter Profile Photo

#Python factlet: functools.partial() self-flattens. Writing: partial(partial(pow, 2), 5) optimizes to: partial(pow, 2, 5) The result is only one layer deep.

Raymond Hettinger (@raymondh) 's Twitter Profile Photo

#Python tip: operator.itemgetter() accepts slice objects. >>> from operator import itemgetter >>> chomp_ends = itemgetter(slice(1, -1)) >>> chomp_ends('abcdefgh') 'bcdefg'

Armin Ronacher ⇌ (@mitsuhiko) 's Twitter Profile Photo

asyncio is still really wild in 2025. I haven't actively written asyncio code in a while but now that I have done it for a week agian, I noticed that most problems from when I used it last are still unresolved. Problem 1: asyncio.create_task is a massive footgun because it can

asyncio is still really wild in 2025. I haven't actively written asyncio code in a while but now that I have done it for a week agian, I noticed that most problems from when I used it last are still unresolved.

Problem 1: asyncio.create_task is a massive footgun because it can
Raymond Hettinger (@raymondh) 's Twitter Profile Photo

#Python musing: From a practical point of view, "infinite" is just a special case of "inconveniently large". There is nothing special about: sum(itertools.count()) as compared to: sum(range(10**20))

Bindu Reddy (@bindureddy) 's Twitter Profile Photo

Overall, AI Is Making Humans More Stupid AI makes 1% of us smarter and the remaining 99% stupider. The 1% are using AI to learn and do things, and know how to use it effectively. The remaining 99% blindly use AI to copy homework, write emails they don't read, try vibe coding,

Raymond Hettinger (@raymondh) 's Twitter Profile Photo

For me, the Desmos Graphing Calculator sparks joy. Its API designers are true craftsmen (and women). The tool is approachable for kids, powerful enough for real world use, and completely devoid of cruft/nonsense. It takes discipline to make something this good.

Raymond Hettinger (@raymondh) 's Twitter Profile Photo

#Python tip: The w in r"\w+" stands for "wrong". False negatives: can't you've Mary's cul-de-sac non-profit False positives: _____ 123 Actual word tokens may include apostrophes and hyphens and may exclude underscores or numbers.

Raymond Hettinger (@raymondh) 's Twitter Profile Photo

#Python teaching tip: If someone says, "I didn't get topic X, can you go over it again" that means that your approach wasn't successful. Don't say the same words over again. Instead, approach the topic from a completely different angle. Home in on what works.

Raymond Hettinger (@raymondh) 's Twitter Profile Photo

#Python teaching tool: To demonstrate testing and debugging, I often use this function: def square(n: int) -> int: return sum(n - 2 for i in range(n + 2)) + 4 Tests pass for n=100, n=7, n=1, n=0, n=-1, and n=-2. But fail for n=-5. Tests can't prove the absence of errors.

Raymond Hettinger (@raymondh) 's Twitter Profile Photo

#Python notes: The Counter in the collections module supports two kinds of arithmetic. The update() and subtract() methods implement normal arithmetic with possible negative numbers in the results. The "+" and "-" implement saturating arithmetic giving non-negative results.

Raymond Hettinger (@raymondh) 's Twitter Profile Photo

#Python recipe of the day: relu = functools.partial(max, 0.0) Presto, you have rectified linear unit for a neural net. geeksforgeeks.org/deep-learning/…