On May 28, 11:13 am, "William Stein" <
wst...@gmail.com> wrote:
> On Wed, May 28, 2008 at 10:59 AM, John H Palmieri
>
>
>
> <
jhpalmier...@gmail.com> wrote:
>
> > Here's the situation: in some sage code that I'm working on, I have a
> > variable, say 'output_format', which tells sage how to print certain
> > kinds of objects (in particular, they are elements of a vector space,
> > and output_format essentially tells sage which basis to use and how to
> > print the basis elements). Right now, users can change the value of
> > output_format explicitly, but I would like to add a method for the
> > class defining my elements so I can type
> > "x.basis('blah')" and have the output printed as if output_format were
> > set to 'blah'.
>
> > In lisp, I could do something like
>
> > (let ((output_format 'blah'))
>
Hi William,
I accidentally posted this before it was ready, and then deleted the
message from the group, but you read it before it got deleted.
> Can you give an example of the code users would currently write
> to change the property, followed by an example of the code you
> wish users could instead write to change the property?
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)
> -- William
--
John