exec - return value of expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christoph Groth

    exec - return value of expression

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.0.6 (GNU/Linux)
    Comment: For info see http://www.gnupg.org

    iD8DBQBALV1mfx2/njzvX5URApX5AJ0 cG9CzO/jCQ6iB9bvsNvfm+ z1xHQCfb1sp
    4Z90gpZPZadJcnM SsueMHWA=
    =fBd6
    -----END PGP SIGNATURE-----
  • Josiah Carlson

    #2
    Re: exec - return value of expression

    > One solution would be to change the __repr__-Methods of the objects[color=blue]
    > 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.[/color]

    Here's a kludge...if you are willing to manually instantiate all lists
    first.
    [color=blue][color=green][color=darkred]
    >>> _list = list
    >>> class list(_list):[/color][/color][/color]
    .... def __repr__(self):
    .... orig = _list.__repr__( self)
    .... return "blah "+orig
    ....[color=blue][color=green][color=darkred]
    >>> a = list()
    >>> a[/color][/color][/color]
    blah [][color=blue][color=green][color=darkred]
    >>> a.append('hello ')
    >>> a[/color][/color][/color]
    blah ['hello'][color=blue][color=green][color=darkred]
    >>> a.extend(['world', 'blah'])
    >>> a[/color][/color][/color]
    blah ['hello', 'world', 'blah']
    [color=blue]
    > Any hints on how to solve this Problem in an elegant way are greatly
    > appreciated.[/color]

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

    - Josiah

    Comment

    • Peter Otten

      #3
      Re: exec - return value of expression

      Christoph Groth wrote:
      [color=blue]
      > 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:
      >[color=green][color=darkred]
      >>>> f = create_some_for mula()
      >>>> tex(f) # Prettyprint the formula[/color][/color]
      >
      > But typing tex( ) all the time is a bit annoying, I would like that
      > the following works inside my texmacs-plugin.
      >[color=green][color=darkred]
      >>>> f = create_some_for mula()
      >>>> f # Prettyprint the formula[/color][/color][/color]

      Have a look at sys.displayhook :
      [color=blue][color=green][color=darkred]
      >>> import sys, __builtin__
      >>> def myhook(a):[/color][/color][/color]
      .... if a is not None:
      .... __builtin__._ = a
      .... sys.stdout.writ e("python proudly presents: %s\n" % a)
      ....[color=blue][color=green][color=darkred]
      >>> sys.displayhook = myhook
      >>> 1[/color][/color][/color]
      python proudly presents: 1[color=blue][color=green][color=darkred]
      >>>[/color][/color][/color]

      Peter

      Comment

      Working...