By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,941 Members | 1,789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,941 IT Pros & Developers. It's quick & easy.

exec - return value of expression

P: n/a
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
> One solution would be to change the __repr__-Methods of the objects
which are to be prettyprinted. This should work, but I would like to
prettyprint some builtin objects too, like a list of formulas for
example. And I don't know how to change the __repr__ of builtin
Here's a kludge...if you are willing to manually instantiate all lists
_list = list
class list(_list): .... def __repr__(self):
.... orig = _list.__repr__(self)
.... return "blah "+orig
.... a = list()
a blah [] a.append('hello')
a blah ['hello'] a.extend(['world', 'blah'])

blah ['hello', 'world', 'blah']
Any hints on how to solve this Problem in an elegant way are greatly

It is not elegant, but it may work for you.

- Josiah
Jul 18 '05 #2

P: n/a
Christoph Groth wrote:
Currently, if the user wants to print some formula, say, he has to
execute a function called `tex' which packages the TeX-representation
of the formula in a way understood by texmacs, like this:
f = create_some_formula()
tex(f) # Prettyprint the formula
But typing tex( ) all the time is a bit annoying, I would like that
the following works inside my texmacs-plugin.
f = create_some_formula()
f # Prettyprint the formula
Have a look at sys.displayhook:
import sys, __builtin__
def myhook(a): .... if a is not None:
.... __builtin__._ = a
.... sys.stdout.write("python proudly presents: %s\n" % a)
.... sys.displayhook = myhook
1 python proudly presents: 1


Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.