Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IDLE - Customizing output format

4 views
Skip to first unread message

Ilias Lazaridis

unread,
Sep 23, 2006, 10:56:06 AM9/23/06
to
IDLE has an output format like this:

>>> object
<type 'object'>
>>> type
<type 'type'>
>>> object.__class__
<type 'type'>
>>> object.__bases__

How can I customize it to become like that:

>>> object
<type 'object'>
>>> type
<type 'type'>
>>> object.__class__
<type 'type'>
>>> object.__bases__

or that:

>>> object
: <type 'object'>
>>> type
: <type 'type'>
>>> object.__class__
: <type 'type'>
>>> object.__bases__

(preferably without modifying code)

.

--
http://lazaridis.com

Ilias Lazaridis

unread,
Sep 24, 2006, 3:29:19 PM9/24/06
to

I assume this is not possible.

I am wondering that other users are not annoyed by this reduced
readability.

anyway.

.

> --
> http://lazaridis.com

Steve Holden

unread,
Sep 24, 2006, 4:28:51 PM9/24/06
to pytho...@python.org
And I am wondering at your continual surprise when the rest of the world
fails to share your perceptions. Doesn't this carry *any* information?

> anyway.
>
Indeed.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Ilias Lazaridis

unread,
Sep 24, 2006, 4:40:43 PM9/24/06
to

not the rest of the world, but the rest of the python community.

That's a big difference.

So it looks that I have to code to change the output format.

Reminds me 'good old days'.

> > anyway.
> >
> Indeed.

Diez B. Roggisch

unread,
Sep 24, 2006, 5:09:18 PM9/24/06
to
>> And I am wondering at your continual surprise when the rest of the world
>> fails to share your perceptions. Doesn't this carry *any* information?
>
> not the rest of the world, but the rest of the python community.
>
> That's a big difference.
>
> So it looks that I have to code to change the output format.
>
> Reminds me 'good old days'.

Gosh. Shocking. A programmer is supposed to program if he wants a
program to behave differently. When the heck has this world mutated from
a place where uttering nonsense made it immediately happen, as if by magic?

I can recall two times that has been the case before:

- paradise. Ended presumably 6000 years ago, according to your local
intelligent designer outlet.

- dot-com era, unfortunately only for funding ideas, not so much
developing or even successfully deploying them. Ended 2001.

Obviously historians have to consider a third period: the golden times
of Illias wishful thinking reign, a collectively unnoticed time which
only records could be found if brain scanning was more developed in just
one brain in the world. Yours.

Diez

Robert Kern

unread,
Sep 24, 2006, 5:55:54 PM9/24/06
to pytho...@python.org
Ilias Lazaridis wrote:
> Steve Holden wrote:

>> And I am wondering at your continual surprise when the rest of the world
>> fails to share your perceptions. Doesn't this carry *any* information?
>
> not the rest of the world, but the rest of the python community.

Remember back when you first came to comp.lang.python and I told you that this
was not the community that you were looking for?

http://mail.python.org/pipermail/python-list/2005-February/266629.html

Good times.

Anyways, against my better judgement, I will tell you that you can customize the
output by replacing sys.displayhook with your own function:

http://www.python.org/doc/current/lib/module-sys.html

>>> import sys
>>> 1
1
>>> def f(obj):
print ' ' + repr(obj)


>>> sys.displayhook = f
>>> 1
1
>>>

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Gabriel Genellina

unread,
Sep 25, 2006, 10:00:56 PM9/25/06
to pytho...@python.org
At Sunday 24/9/2006 18:55, Robert Kern wrote:

>Anyways, against my better judgement, I will tell you that you can
>customize the
>output by replacing sys.displayhook with your own function:
>
> http://www.python.org/doc/current/lib/module-sys.html
>
> >>> import sys

> >>> def f(obj):
> print ' ' + repr(obj)
> >>> sys.displayhook = f

Sometimes I enable a similar approach on my sitecustomize.py, using
the pprint module. But I don't *always* like the output format.


Gabriel Genellina
Softlab SRL





__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

James Stroud

unread,
Sep 26, 2006, 3:57:28 AM9/26/06
to

I'm sure its quite unpopular to agree with you, but I do. I am
tremendously annoyed the format of the interactive interpreter. Lovely
would be output as you describe, but with the option, when selecting for
copy-paste, to include the prompts and/or your suggested whitespace
margin (e.g. select in doctest mode).

James

Ilias Lazaridis

unread,
Sep 26, 2006, 2:29:14 PM9/26/06
to
Robert Kern wrote:
> Ilias Lazaridis wrote:
> > Steve Holden wrote:
>
> >> And I am wondering at your continual surprise when the rest of the world
> >> fails to share your perceptions. Doesn't this carry *any* information?
> >
> > not the rest of the world, but the rest of the python community.
>
> Remember back when you first came to comp.lang.python and I told you that this
> was not the community that you were looking for?
>
> http://mail.python.org/pipermail/python-list/2005-February/266629.html
>
> Good times.

yes, good times, for the memory:

http://case.lazaridis.com/wiki/PythonAudit

but now I produce (using python):

http://dev.lazaridis.com/base

> Anyways, against my better judgement, I will tell you that you can customize the
> output by replacing sys.displayhook with your own function:
>
> http://www.python.org/doc/current/lib/module-sys.html
>
> >>> import sys
> >>> 1
> 1
> >>> def f(obj):
> print ' ' + repr(obj)
>
> >>> sys.displayhook = f
> >>> 1
> 1
> >>>

I've placed this code within /Lib/sitecustomize.py, but have one
strange result:

>>> from talker import *
>>> t = Talker()
>>> t.sayHello
: <bound method Talker.sayHello of <talker.Talker instance at
0x00DEA198>>
>>> t.sayHello()
Hello world
: None
>>>

1st: "Hello world" comes still on the beginning.
2nd: I got this "None"


class Talker:
def sayHello(self):
print 'Hello world'

def talk(self):
self.sayHello()

Ilias Lazaridis

unread,
Sep 26, 2006, 2:31:37 PM9/26/06
to

Gabriel Genellina wrote:
> At Sunday 24/9/2006 18:55, Robert Kern wrote:
>
> >Anyways, against my better judgement, I will tell you that you can
> >customize the
> >output by replacing sys.displayhook with your own function:
> >
> > http://www.python.org/doc/current/lib/module-sys.html
> >
> > >>> import sys
> > >>> def f(obj):
> > print ' ' + repr(obj)
> > >>> sys.displayhook = f
>
> Sometimes I enable a similar approach on my sitecustomize.py, using
> the pprint module. But I don't *always* like the output format.

Can you please show this approach using "pprint"?

.

Robert Kern

unread,
Sep 26, 2006, 2:47:08 PM9/26/06
to pytho...@python.org
Ilias Lazaridis wrote:
> Robert Kern wrote:

>> Anyways, against my better judgement, I will tell you that you can customize the
>> output by replacing sys.displayhook with your own function:
>>
>> http://www.python.org/doc/current/lib/module-sys.html
>>
>> >>> import sys
>> >>> 1
>> 1
>> >>> def f(obj):
>> print ' ' + repr(obj)
>>
>> >>> sys.displayhook = f
>> >>> 1
>> 1
>> >>>
>
> I've placed this code within /Lib/sitecustomize.py, but have one
> strange result:
>
>>>> from talker import *
>>>> t = Talker()
>>>> t.sayHello
> : <bound method Talker.sayHello of <talker.Talker instance at
> 0x00DEA198>>
>>>> t.sayHello()
> Hello world
> : None
>
> 1st: "Hello world" comes still on the beginning.

Yes. Read the doc for sys.displayhook() and you will understand why.

> 2nd: I got this "None"

Yes. Read the doc for sys.displayhook() and you will understand why.

I did not give you an all-singing, all-dancing solution, just showed you that
you *can* customize the output that you said you wanted customized.

Ilias Lazaridis

unread,
Sep 26, 2006, 2:51:20 PM9/26/06
to
James Stroud wrote:
> Ilias Lazaridis wrote:
...

> > I am wondering that other users are not annoyed by this reduced
> > readability.
>
> I'm sure its quite unpopular to agree with you, but I do. I am
> tremendously annoyed the format of the interactive interpreter. Lovely
> would be output as you describe, but with the option, when selecting for
> copy-paste, to include the prompts and/or your suggested whitespace
> margin (e.g. select in doctest mode).
>
> James

I am not sure I understand what you meen with the option.

copy includes both, the ">>>" and the " :"

possibly you can elaborate a little, as this could be an important
factor.

-

As for a solution to the output, just follow this ticket:

http://case.lazaridis.com/ticket/10

.

Gabriel Genellina

unread,
Sep 26, 2006, 7:30:35 PM9/26/06
to Ilias Lazaridis, pytho...@python.org
At Tuesday 26/9/2006 15:31, Ilias Lazaridis wrote:

> > >Anyways, against my better judgement, I will tell you that you can
> > >customize the
> > >output by replacing sys.displayhook with your own function:
> > >
> > > http://www.python.org/doc/current/lib/module-sys.html
> > >
> > > >>> import sys
> > > >>> def f(obj):
> > > print ' ' + repr(obj)
> > > >>> sys.displayhook = f
> >
> > Sometimes I enable a similar approach on my sitecustomize.py, using
> > the pprint module. But I don't *always* like the output format.
>
>Can you please show this approach using "pprint"?

Sure. Put these two lines into your sitecustomize.py:

import sys, pprint
sys.displayhook = pprint.pprint

and see what happens when you eval things inside the interpreter.

Gabriel Genellina

unread,
Sep 26, 2006, 7:34:55 PM9/26/06
to Ilias Lazaridis, pytho...@python.org
At Tuesday 26/9/2006 15:29, Ilias Lazaridis wrote:

> > >>> def f(obj):
> > print ' ' + repr(obj)
> >
> > >>> sys.displayhook = f
>

>I've placed this code within /Lib/sitecustomize.py, but have one
>strange result:
>
> >>> from talker import *
> >>> t = Talker()
> >>> t.sayHello
> : <bound method Talker.sayHello of <talker.Talker instance at
>0x00DEA198>>
> >>> t.sayHello()
>Hello world
> : None
> >>>
>
>1st: "Hello world" comes still on the beginning.
>2nd: I got this "None"

The replacement should be a bit more complicated, taking None into
account - see the original PEP for details
http://www.python.org/dev/peps/pep-0217/
And notice that this replaces the output of *evaluated* expressions,
not any print statement executed inside your code.

James Stroud

unread,
Sep 27, 2006, 12:42:16 AM9/27/06
to
Ilias Lazaridis wrote:
> James Stroud wrote:
>>Ilias Lazaridis wrote:
>>>I am wondering that other users are not annoyed by this reduced
>>>readability.
>>
>>I'm sure its quite unpopular to agree with you, but I do. I am
>>tremendously annoyed the format of the interactive interpreter. Lovely
>>would be output as you describe, but with the option, when selecting for
>>copy-paste, to include the prompts and/or your suggested whitespace
>>margin (e.g. select in doctest mode).
>>
> I am not sure I understand what you meen with the option.
>
> copy includes both, the ">>>" and the " :"
>
> possibly you can elaborate a little, as this could be an important
> factor.

Well, for example, the output (I'm indenting manually for visual clarity):

>>> print 'bob'
: bob
>>> print [i for i in xrange(3)]
: [0, 1, 2]


Would create the following selection in "doctest" mode (again manually
adding whitespace):

>>> print 'bob'
bob
>>> print [i for i in xrange(3)]
[0, 1, 2]


But, say for 'code copy' mode, this selection would be appended to the
clipboard (again manually adding whitespace for clarity):

print 'bob'
print [i for i in xrange(3)]


This way you could either make doctest blocks or copy code drafted in
the interactive interpreter. I often get carried away and write complete
useful functions in the interpreter then have to do commands like the
following in vim:

:.,+8s/^....//

to fix ">"s and ellipses, etc., in the copied function. Or if I want to
tweak a function I'm writing in the interpreter, I painfully copy it one
line at a time. This may or may not be the best way to use the
interpreter (to draft actual code) but I find myself doing it all of the
time.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/

Ilias Lazaridis

unread,
Sep 27, 2006, 8:11:13 AM9/27/06
to
James Stroud wrote:
> Ilias Lazaridis wrote:
...

> Well, for example, the output (I'm indenting manually for visual clarity):
>
> >>> print 'bob'
> : bob
> >>> print [i for i in xrange(3)]
> : [0, 1, 2]
>
>
> Would create the following selection in "doctest" mode (again manually
> adding whitespace):
>
> >>> print 'bob'
> bob
> >>> print [i for i in xrange(3)]
> [0, 1, 2]

http://docs.python.org/lib/module-doctest.html

ok, I understand now.

then, for consistency reasons, the ":" could become ":::".

doctest would need to get a tiny addition to be able to 'see' those
":::".

> But, say for 'code copy' mode, this selection would be appended to the
> clipboard (again manually adding whitespace for clarity):
>
> print 'bob'
> print [i for i in xrange(3)]

I understand.

> This way you could either make doctest blocks or copy code drafted in
> the interactive interpreter. I often get carried away and write complete
> useful functions in the interpreter then have to do commands like the
> following in vim:
>
> :.,+8s/^....//
>
> to fix ">"s and ellipses, etc., in the copied function. Or if I want to
> tweak a function I'm writing in the interpreter, I painfully copy it one
> line at a time. This may or may not be the best way to use the
> interpreter (to draft actual code) but I find myself doing it all of the
> time.

I am wondering that this functionality (copy code) is not included
within IDLE.

It should be possible to add it quite simple.

.

Ilias Lazaridis

unread,
Sep 27, 2006, 8:29:48 AM9/27/06
to
Gabriel Genellina wrote:
> At Tuesday 26/9/2006 15:29, Ilias Lazaridis wrote:
>
> > > >>> def f(obj):
> > > print ' ' + repr(obj)
> > >
> > > >>> sys.displayhook = f
> >
> >I've placed this code within /Lib/sitecustomize.py, but have one
> >strange result:
...
> > >>> t.sayHello()
> >Hello world
> > : None

> >1st: "Hello world" comes still on the beginning.
> >2nd: I got this "None"

import sys
def f(obj):
if obj:


print '::: ' + repr(obj)
sys.displayhook = f

> The replacement should be a bit more complicated, taking None into


> account - see the original PEP for details
> http://www.python.org/dev/peps/pep-0217/
> And notice that this replaces the output of *evaluated* expressions,
> not any print statement executed inside your code.

Any simple solution for this?

I've looked a little at the code, but get immediately demotivated
seeing 72 files within a flat directroy:

http://svn.python.org/view/python/trunk/Lib/idlelib/?rev=52013

.

--
http://lazaridis.com

Gabriel Genellina

unread,
Sep 27, 2006, 11:41:27 PM9/27/06
to Ilias Lazaridis, pytho...@python.org
At Wednesday 27/9/2006 09:29, Ilias Lazaridis wrote:

>import sys
>def f(obj):
> if obj:
> print '::: ' + repr(obj)
>sys.displayhook = f

Have you tried that? You have to filter out None, not *any* False value.

> > And notice that this replaces the output of *evaluated* expressions,
> > not any print statement executed inside your code.
>
>Any simple solution for this?

Displaying things interactively is not the same as executing a print
statement inside the code - I feel right they are not considered the
same thing.
print output goes to sys.stdout, you could replace it.

>I've looked a little at the code, but get immediately demotivated
>seeing 72 files within a flat directroy:
>
>http://svn.python.org/view/python/trunk/Lib/idlelib/?rev=52013

Remember that packages have not existed forever... I've seen worse things :)

Ilias Lazaridis

unread,
Sep 28, 2006, 6:28:22 PM9/28/06
to
Gabriel Genellina wrote:
> At Wednesday 27/9/2006 09:29, Ilias Lazaridis wrote:
>
> >import sys
> >def f(obj):
> > if obj:
> > print '::: ' + repr(obj)
> >sys.displayhook = f
>
> Have you tried that? You have to filter out None, not *any* False value.

you are right. 1 == 0 showed an empty response.

this one seems to work:

def f(obj):
if obj is not None:
print '::: ' + repr(obj)

> > > And notice that this replaces the output of *evaluated* expressions,
> > > not any print statement executed inside your code.
> >
> >Any simple solution for this?
>
> Displaying things interactively is not the same as executing a print
> statement inside the code - I feel right they are not considered the
> same thing.

agree.

> print output goes to sys.stdout, you could replace it.

wouldn't this replace all sdtout of every python programm?

i've tried this one:

sys.sdtout = f

without success within IDLE.

> >I've looked a little at the code, but get immediately demotivated
> >seeing 72 files within a flat directroy:
> >
> >http://svn.python.org/view/python/trunk/Lib/idlelib/?rev=52013
>
> Remember that packages have not existed forever... I've seen worse things :)

ok, me too.

but placing at minimum 2 directories like:

core
gui

could simpify things already very much.

.

--
http://lazaridis.com

Ilias Lazaridis

unread,
Oct 7, 2006, 7:11:24 PM10/7/06
to
Gabriel Genellina wrote:
> At Wednesday 27/9/2006 09:29, Ilias Lazaridis wrote:
>
> >import sys
> >def f(obj):
> > if obj:
> > print '::: ' + repr(obj)
> >sys.displayhook = f
>
> Have you tried that? You have to filter out None, not *any* False value.
>
> > > And notice that this replaces the output of *evaluated* expressions,
> > > not any print statement executed inside your code.
> >
> >Any simple solution for this?
>
> Displaying things interactively is not the same as executing a print
> statement inside the code - I feel right they are not considered the
> same thing. print output goes to sys.stdout, you could replace it.

this is nicely described here:

http://www.voidspace.org.uk/python/weblog/arch_d7_2006_01_21.shtml#e192

do i need the "getattr" and "writeline" methods in MyStdOut?

.

--
http://case.lazaridis.com/ticket/10

Ilias Lazaridis

unread,
Oct 7, 2006, 7:59:20 PM10/7/06
to

I am close to finalizing this task, but have two tiny problems:

import the module from within a site_packages *.pth file, or
include the code into sitecustomize, or
import it withine an IDLE session:

# idlex.py
#---------------------------------------------------------------------------------------
import sys

class ClaimStdOut:
def __init__(self, stream, prefix):
self.stdout = stream #remember original stream
self.prefix = prefix

def write(self, output):
self.stdout.write(self.prefix + output)


#this one is _not_ executed on import:
sys.stdout = ClaimStdOut(sys.stdout, '=== ')

#workaround:


def f(obj):
if obj is not None:

print repr(obj)
# Claiming StdOut here
sys.stdout = ClaimStdOut(sys.stdout, '::: ')
#disable displayhook (which is just used to set stdout)
sys.displayhook = sys.__displayhook__

# this one _is_ executed on import
sys.displayhook = f
#---------------------------------------------------------------------------------------

So, why is this line not executed during import?

sys.stdout = ClaimStdOut(sys.stdout, '=== ')

additionally, the output of IDLE looks like this:

IDLE 1.1.3 ==== No Subprocess ====
>>> 1==1
True
[the new stdout is active now]
>>> 1==1
::: True:::
>>>

Possibly IDLE prints the CR/LF in a second call.

How can I compare this operating-system-independent?

if (output == <os.line-end-marker>):
self.stdout.write(output)
else:
self.stdout.write(self.prefix + output)

.

--
http://case.lazaridis.com/ticket/10

0 new messages