[issue2610] string representation of range and dictionary views

Brad Miller report at bugs.python.org
Tue Mar 10 20:13:31 CET 2009


Brad Miller <bonelake at gmail.com> added the comment:

Just to restart the discussion on the original issue since I see that 
the latest 3.1 has solved the problem with dict_keys, dict_values, etc 
al objects.  Many thanks!

A suggestion was made by Alexander to create a custom displayhook that 
could be included in the standard library.  From the research I've done 
it looks like a solution for range would be something like the 
following:

import sys
def eduhook(o):
    if o is None:
        return
    if isinstance(o,range):
        print(list(o))
    else:
        print(repr(o))
        
sys.displayhook = eduhook

Now if 5233/5234 were approved I could tell my students to setup an 
environment variable PYTHONSTARTUP that points to a file that imports a 
module containing the above code.  (or I could just tell them to import 
said module each time.)

The above hook appears to work fine.  Is there anything obvious I'm 
missing?  If this is along the right track then I could extend it to 
support other custom display ideas that my fellow educators have in 
mind.

Thanks,

Brad

----------
message_count: 30.0 -> 31.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue2610>
_______________________________________


More information about the Python-bugs-list mailing list