<p dir="ltr"><br>
On 16 Dec 2013 02:58, "Ethan Furman" <<a href="mailto:ethan@stoneleaf.us">ethan@stoneleaf.us</a>> wrote:<br>
><br>
> On 12/14/2013 07:51 PM, Steven D'Aprano wrote:<br>
>><br>
>> On Sun, Dec 15, 2013 at 11:25:10AM +1000, Nick Coghlan wrote:<br>
>><br>
>>> Oh, yes, a %T shortcut for "length limited type name of the supplied<br>
>>> object" would be brilliant. We need this frequently for C level error<br>
>>> messages, and I almost always have to look at an existing example to<br>
>>> remember the exact incantation :)<br>
>><br>
>><br>
>> What are the chances that could be made available from pure Python too?<br>
>> Having to extract the name of the type is a very common need for error<br>
>> messages, and I never know whether I ought to write type(obj).__name__<br>
>> or obj.__class__.__name__. A %T and/or {:T} format code could be the One<br>
>> Obvious Way to include the type name in strings<br>
><br>
><br>
> +1</p>
<p dir="ltr">It's less obviously correct for Python code, though. In C, we're almost always running off slots, so type(obj).__name__ has a very high chance of being what we want, and is also preferred for speed reasons (since it's just a couple of pointer dereferences).</p>

<p dir="ltr">At the Python level, whether to display obj.__name__ (working with a class directly), type(obj).__name__ (working with the concrete type, ignoring any proxying) or obj.__class__.__name__ (which takes proxying into account) really depends on exactly what you're doing, and the speed differences between them aren't so stark.</p>

<p dir="ltr">Cheers,<br>
Nick.</p>
<p dir="ltr">><br>
> --<br>
> ~Ethan~<br>
><br>
> _______________________________________________<br>
> Python-Dev mailing list<br>
> <a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-dev">https://mail.python.org/mailman/listinfo/python-dev</a><br>
> Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com">https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com</a><br>
</p>