#1918: Matrices that are printed are not aligned
------------------------------+---------------------------------------------
Reporter: jason | Owner: was
Type: enhancement | Status: positive_review
Priority: major | Milestone: sage-4.3
Component: linear algebra | Keywords:
Work_issues: | Author: Bill Cauchois
Upstream: N/A | Reviewer: Florent Hivert
Merged: |
------------------------------+---------------------------------------------
Comment(by wcauchois):
Replying to [comment:14 hivert]:
> I've a request concerning this ticket: You manage to hijack ipython's
printer but not python's one.
> {{{
> sage: [matrix(2,2)] * 3
> [
> [0 0] [0 0] [0 0]
> [0 0], [0 0], [0 0]
> ]
> sage: print([matrix(2,2)] * 3)
> [[0 0]
> [0 0], [0 0]
> [0 0], [0 0]
> [0 0]]
> }}}
> Is it trivial to solve this ? Or should I open a new ticket ?
You raise an interesting point Florent. The problem here is that Python's
displayhook mechanism only affects the output from the interpreter, not
the behavior of the print statement. In fact, the displayhook uses the
print statement to output values, so if the print statement used the
displayhook it would be bad.
AFAIK, there is no way to hook into the print statement. All it does is
write the object's repr to sys.stdout. And now we run into the limitation
that drove us to use a displayhook in the first place: you can't change
the way repr behaves for lists.
The only thing I can suggest is to add a function, say,
{{{format_list_of_matrices()}}} to the matrix library so that your code
becomes:
{{{
sage: print format_list_of_matrices([matrix(2,2) * 3])
}}}
But I feel like such a facility would be not at all obvious for end-users.
Unless they notice how crappy a list of matrices looks when its
{{{print}}}ed and root around the documentation for answers.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/1918#comment:15>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.