469,621 Members | 1,748 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

IDLE - Customizing output format

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
Sep 23 '06 #1
20 1660
Ilias Lazaridis wrote:
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)
I assume this is not possible.

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

anyway.

..
--
http://lazaridis.com
Sep 24 '06 #2
Ilias Lazaridis wrote:
Ilias Lazaridis wrote:
>>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)


I assume this is not possible.

I am wondering that other users are not annoyed by this reduced
readability.
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

Sep 24 '06 #3
Steve Holden wrote:
Ilias Lazaridis wrote:
Ilias Lazaridis wrote:
>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)
I assume this is not possible.

I am wondering that other users are not annoyed by this reduced
readability.
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'.
anyway.
Indeed.
Sep 24 '06 #4
>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
Sep 24 '06 #5
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/pyt...ry/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

Sep 24 '06 #6
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

Sep 26 '06 #7
Ilias Lazaridis wrote:
Ilias Lazaridis wrote:
>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)

I assume this is not possible.

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
Sep 26 '06 #8
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/pyt...ry/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()

Sep 26 '06 #9

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"?

..

Sep 26 '06 #10
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.

--
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

Sep 26 '06 #11
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

..

Sep 26 '06 #12
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
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

Sep 26 '06 #13
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.
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

Sep 26 '06 #14
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/
Sep 27 '06 #15
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.

..

Sep 27 '06 #16
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/tr...lib/?rev=52013

..

--
http://lazaridis.com

Sep 27 '06 #17
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/tr...lib/?rev=52013
Remember that packages have not existed forever... I've seen worse things :)
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

Sep 28 '06 #18
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/tr...lib/?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

Sep 28 '06 #19
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/w..._21.shtml#e192

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

..

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

Oct 7 '06 #20

Ilias Lazaridis wrote:
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)
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

Oct 7 '06 #21

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Kerry Neilson | last post: by
4 posts views Thread by Bill Davy | last post: by
13 posts views Thread by John Salerno | last post: by
5 posts views Thread by heidi.hunter | last post: by
11 posts views Thread by aaragon | last post: by
2 posts views Thread by thecoolone | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.