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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQBALV1mfx2/njzvX5URApX5AJ0cG9CzO/jCQ6iB9bvsNvfm+z1xHQCfb1sp
4Z90gpZPZadJcnMSsueMHWA=
=fBd6
-----END PGP SIGNATURE-----
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
lists.
Here's a kludge...if you are willing to manually instantiate all lists
first.
_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'])
a

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


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


Peter

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.