<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom"><title>Simon Willison's Weblog: trey-hunner</title><link href="http://simonwillison.net/" rel="alternate"/><link href="http://simonwillison.net/tags/trey-hunner.atom" rel="self"/><id>http://simonwillison.net/</id><updated>2025-03-03T19:15:30+00:00</updated><author><name>Simon Willison</name></author><entry><title>The features of Python's help() function</title><link href="https://simonwillison.net/2025/Mar/3/pythons-help-function/#atom-tag" rel="alternate"/><published>2025-03-03T19:15:30+00:00</published><updated>2025-03-03T19:15:30+00:00</updated><id>https://simonwillison.net/2025/Mar/3/pythons-help-function/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.pythonmorsels.com/help-features/"&gt;The features of Python&amp;#x27;s help() function&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
I've only ever used Python's &lt;code&gt;help()&lt;/code&gt; feature by passing references to modules, classes functions and objects to it. Trey Hunner just taught me that it accepts strings too - &lt;code&gt;help("**")&lt;/code&gt; tells you about the &lt;code&gt;**&lt;/code&gt; operator, &lt;code&gt;help("if")&lt;/code&gt; describes the &lt;code&gt;if&lt;/code&gt; statement and &lt;code&gt;help("topics")&lt;/code&gt; reveals even more options, including things like &lt;code&gt;help("SPECIALATTRIBUTES")&lt;/code&gt; to learn about specific advanced topics.

    &lt;p&gt;&lt;small&gt;&lt;/small&gt;Via &lt;a href="https://bsky.app/profile/trey.io/post/3ljimzwglik2n"&gt;@trey.io&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/python"&gt;python&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/trey-hunner"&gt;trey-hunner&lt;/a&gt;&lt;/p&gt;



</summary><category term="python"/><category term="trey-hunner"/></entry><entry><title>Python 3.13's best new features</title><link href="https://simonwillison.net/2024/Oct/12/python-313s-best-new-features/#atom-tag" rel="alternate"/><published>2024-10-12T16:30:42+00:00</published><updated>2024-10-12T16:30:42+00:00</updated><id>https://simonwillison.net/2024/Oct/12/python-313s-best-new-features/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.pythonmorsels.com/python-313-whats-new/"&gt;Python 3.13&amp;#x27;s best new features&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
Trey Hunner highlights some Python 3.13 usability improvements I had missed, mainly around the new REPL.&lt;/p&gt;
&lt;p&gt;Pasting a block of code like a class or function that includes blank lines no longer breaks in the REPL - particularly useful if you frequently have LLMs write code for you to try out.&lt;/p&gt;
&lt;p&gt;Hitting F2 in the REPL toggles "history mode" which gives you your Python code without the REPL's &lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt; and &lt;code&gt;...&lt;/code&gt; prefixes - great for copying code back out again.&lt;/p&gt;
&lt;p&gt;Creating a virtual environment with &lt;code&gt;python3.13 -m venv .venv&lt;/code&gt; now adds a &lt;code&gt;.venv/.gitignore&lt;/code&gt; file containing &lt;code&gt;*&lt;/code&gt; so you don't need to explicitly ignore that directory. I just checked and it looks like &lt;code&gt;uv venv&lt;/code&gt; &lt;a href="https://github.com/astral-sh/uv/blob/d12d569f24150d3e78dce87a9abf2313b9edac06/crates/uv-virtualenv/src/virtualenv.rs#L145-L146"&gt;implements the same trick&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;And my favourite:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Historically, any line in the Python debugger prompt that started with a PDB command would usually trigger the PDB command, &lt;strong&gt;instead of PDB interpreting the line as Python code.&lt;/strong&gt; [...]&lt;/p&gt;
&lt;p&gt;But now, &lt;strong&gt;if the command looks like Python code, &lt;code&gt;pdb&lt;/code&gt; will run it as Python code!&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Which means I can finally call &lt;code&gt;list(iterable)&lt;/code&gt; in my &lt;code&gt;pdb&lt;/code&gt; seesions, where previously I've had to use &lt;code&gt;[i for i in iterable]&lt;/code&gt; instead.&lt;/p&gt;
&lt;p&gt;(Tip &lt;a href="https://twitter.com/treyhunner/status/1845152386433810521"&gt;from Trey&lt;/a&gt;: &lt;code&gt;!list(iterable)&lt;/code&gt; and &lt;code&gt;[*iterable]&lt;/code&gt; are good alternatives for pre-Python 3.13.)&lt;/p&gt;
&lt;p&gt;Trey's post is also available &lt;a href="https://www.youtube.com/watch?v=OBUMQR_YIgs"&gt;as a YouTube video&lt;/a&gt;.

    &lt;p&gt;&lt;small&gt;&lt;/small&gt;Via &lt;a href="https://mastodon.social/@treyhunner/113288613852262515"&gt;@treyhunner&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/python"&gt;python&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/trey-hunner"&gt;trey-hunner&lt;/a&gt;&lt;/p&gt;



</summary><category term="python"/><category term="trey-hunner"/></entry><entry><title>Every dunder method in Python</title><link href="https://simonwillison.net/2024/Mar/20/every-dunder-method-in-python/#atom-tag" rel="alternate"/><published>2024-03-20T03:45:58+00:00</published><updated>2024-03-20T03:45:58+00:00</updated><id>https://simonwillison.net/2024/Mar/20/every-dunder-method-in-python/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.pythonmorsels.com/every-dunder-method/"&gt;Every dunder method in Python&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
Trey Hunner: "Python includes 103 'normal' dunder methods, 12 library-specific dunder methods, and at least 52 other dunder attributes of various types."&lt;/p&gt;
&lt;p&gt;This cheat sheet doubles as a tour of many of the more obscure corners of the Python language and standard library.&lt;/p&gt;
&lt;p&gt;I did not know that Python has over 100 dunder methods now! Quite a few of these were new to me, like &lt;code&gt;__class_getitem__&lt;/code&gt; which can be used to implement type annotations such as &lt;code&gt;list[int]&lt;/code&gt;.


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/python"&gt;python&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/trey-hunner"&gt;trey-hunner&lt;/a&gt;&lt;/p&gt;



</summary><category term="python"/><category term="trey-hunner"/></entry></feed>