>
> On 22 Aug., 00:57, William Stein <wst...@gmail.com> wrote:
>> On Fri, Aug 21, 2009 at 3:18 PM, Simon King <simon.k...@nuigalway.ie> wrote:
> [...]
>>> sage: print M.str()
>>> but there might be nicer (and more intuitive!) ways.
>>
>> I think that is the only way. I can't think of any nicer way. Any idea
>> what it *should* be?
>
> sage: M
> 29 x 29 dense matrix over Integer Ring
> sage: print M
> [ 100 201 892 ...
>
> In other words: If the user types a *command* to display M, then one
> can assume that (s)he really wants to see something (here: content of
> M). But if M is addressed without a command, it might be better to not
> confront the user with lengthy data.
>
> It's just a version of "explicit is better than implicit" - namely
> "using a command means more than not using a command".
> Therefore I believe that __repr__() should not necessarily coincide
> with __str__().
One problem with this is that then one can't do "print M" and get what one
expects from a non-terminal line (e.g. inside a function, or anything but
the last line of a notebook cell).
> Why do I think that "print M.str()" is not intuitive? Since it is
> *two* commands, str() and print (without print it looks ugly).
> So, better might be a method with a descriptive name such as
> "prettyprint", "display", "print_all", etc. that returns None (rather
> than a string) but prints M to stdout.
>
> One problem in that approach is that there is already show() and plot
> () and so on. So, if there are too many display-related methods, it
> might be difficult to tell them apart. Perhaps: show() uses graphic,
> display() uses ascii art.
+1 to somethign like display().
Really, there should be a way to set a threshold for something like this.
- Robert
Can you elaborate? I'm not sure what you're trying to say---what would
one expect? I thought Simon was saying that print M would lead a user
to expect the matrix to be printed out.
I find print M.str() frustrating to remember, so I'm glad this may be
resolved now. I typically first try "M", and then my natural instinct
is to try "print M", thinking that if I tell Sage that I really want it
to print everything out, it will.
Thanks,
Jason
Of course, you'd probably do repr(M) instead, which is more standard
Python. But that's not something I'd expect someone to be able to guess
naturally. And I don't think using repr would work anyway, since that
is what is used for output when you just type M.
print M prints M.__str__()
M by itself prints out M.__repr__()
> A configuration object would be a nice thing to have. And perhaps
> *additionally* a display method that shows the matrix no matter what.
>
+1 on a function that does this, without having to set an attribute. +1
also on making sure that we don't keep adding more and more
special-purpose display functions without making them have some sort of
consistent scheme. +1 also on making the "display" function name
somehow indicate how it is different than "show" or "prettyprint" or
other similar-sounding functions.
Jason
--
Jason Grout