On May 28, 12:35 pm, Carl Witty <[EMAIL PROTECTED]> wrote:
> On May 28, 11:48 am, John H Palmieri <[EMAIL PROTECTED]> wrote:
>
>
>
> > I currently have a function, set_output_format, so users can do this:
>
> > sage: set_output_format('old')
> > 'old'
> > sage: x = (blah); x
> > (x printed in 'old' format)
>
> > I would like to be able to do this:
>
> > sage: x.format('new')
> > (x printed in 'new' format)
> > sage: x # output_format should still be set to 'old'
> > (x printed in 'old' format)
>
> > Anyway, I've almost solved my problem (using a try...finally...
> > block). Now my question is this: is there an existing sage command
> > which does this:
>
> > if in notebook mode and typeset box is on:
> > view(x)
> > else:
> > print(x)
>
> > Then I can do:
>
> > try:
> > old = set_output_format() # with no arguments, set_output_format
> > returns the current format
> > set_output_format(new)
> > fancy_print_command(x) # which behaves as I described above
> > finally:
> > set_output_format(old)
>
> You should look at the Python "with" statement (http://docs.python.org/
> ref/with.html; see alsohttp://docs.python.org/ref/context-managers.html).
> You could implement a function "output_format" so that:
>
> with output_format(new):
> fancy_print_command(x)
>
> is the equivalent of your try-finally block above.
>
> Carl
Thanks, that looks like a good thing to know about.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---