[Python-ideas] Reprs of classes and functions (original) (raw)
Andrew Barnert abarnert at yahoo.com
Thu Feb 26 03:03:02 CET 2015
- Previous message: [Python-ideas] Reprs of classes and functions
- Next message: [Python-ideas] Reprs of classes and functions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
My first response seems to have bounced, so:
Besides backward compatibility, there's still a minor downside to that: the current behavior helps catch some novice errors, like storing a function instead of calling the function and storing its return value. Printing <function spam.cook
> instead of the expected spam, spam, eggs, beans, spam
is a lot more obvious than seeing cook
alone. But as I said, it's pretty minor. It's still not that hard to understand from cook
, especially if you ask someone for help, and this is the kind of mistake that novices only make once (and usually ask for help with). The benefit to everyone surely outweighs the small cost to novices.
Sent from a random iPhone
On Feb 25, 2015, at 8:21, Guido van Rossum <guido at python.org> wrote:
A variant I've often wanted is to make str() return the "clean" type only (e.g. 'int') while leaving repr() alone -- this would address most problems Steven brought up.
On Wed, Feb 25, 2015 at 12:12 AM, Serhiy Storchaka <storchaka at gmail.com> wrote: This idea is already casually mentioned, but sank deep into the threads of the discussion. Raise it up.
Currently reprs of classes and functions look as: >>> int <class 'int'> >>> int.frombytes <built-in method frombytes of type object at 0x826cf60> >>> open >>> import collections >>> collections.Counter <class 'collections.Counter'> >>> collections.Counter.fromkeys <bound method Counter.fromkeys of <class 'collections.Counter'>> >>> collections.namedtuple <function namedtuple at 0xb6fc4adc> What if change default reprs of classes and functions to just full qualified name module + '.' + qualname (or just qualname if module is builtins)? This will look more neatly. And such reprs are evaluable.
Python-ideas mailing list Python-ideas at python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/ -- --Guido van Rossum (python.org/~guido)
Python-ideas mailing list Python-ideas at python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150225/3fc9fccd/attachment.html>
- Previous message: [Python-ideas] Reprs of classes and functions
- Next message: [Python-ideas] Reprs of classes and functions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]