>>> 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
> 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
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.
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
>> 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
>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
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
yes, good times, for the memory:
http://case.lazaridis.com/wiki/PythonAudit
but now I produce (using python):
> 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()
Can you please show this approach using "pprint"?
.
>> 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.
> > 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
.
> > >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.
> > >>> 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.
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://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.
.
> >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
.
>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 :)
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.
.
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?
.
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)
.