exec - return value of expression

C

Christoph Groth

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

Josiah Carlson

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

Peter Otten

Christoph said:
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:


But typing tex( ) all the time is a bit annoying, I would like that
the following works inside my texmacs-plugin.

Have a look at sys.displayhook:
.... if a is not None:
.... __builtin__._ = a
.... sys.stdout.write("python proudly presents: %s\n" % a)
....
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top