On Jun 11, 2012, at 5:36 AM, Chris Smith <smi...@gmail.com> wrote:

> On Mon, Jun 11, 2012 at 4:05 PM, Tom Bachmann <e_mc...@web.de> wrote:
>> Well, I think we should figure out what the various printing methods should
>> do. As far as I can tell we have:
>>
>> - plain str/repr (the same for technical reasons)
>
> Aaron and Vinzent know more about this than I do. There was some
> discussion some time ago about this. (I don't have the ref at hand.)

It's because of a Python "bug", which is that str(list) calls repr on
the elements. Thus if we actually used srepr for repr, output of
functions like solve would produce the ridiculously verbose output of
srepr. Note that I write "bug" in quotes because the Python core devs
have no intention of changing this behavior.

>
>> - sstr and srepr
>> - pprint
>>
>> Now, as I see it, pprint is really what we use interactively. Depending on
>> the environment it might be ascii, unicode or latex, but in any case this is
>> the one that is supposed to look good. The main use of sstr is in doctests.
>> When is plain str ever used?
>
> That's almost all I ever see as the output in an interactive session.

I recommend calling init_printing() at the beginning of your sessions
for your own sanity. Or init_session(), which will also import
everything for you.

>
>>
>> As far as I can see, pprint should just look good, and "str" should produce
>> something that, when passed to sympify, recreates the expression. What about
>> sstr?
>
> I don't know.

str() calls __str__() which calls sstr(). There is no difference.

>
>> From my taxonomy above, sstr is also output-oriented, and as such
>> there does not seem to be a need for this to recreate the original
>> expression upon sympify.
>
>> Which of course would mean that the current
>> quasi-2d printing is fine, so I must be misunderstanding things...
>
> The only thing you can copy and paste into sympify (presently) is
> srepr(matrix). So the changes I proposed was to make the sstr output,
> that is used in the interactive setting, give something that is
> sympifiable:
>
> in my mprint branch:
>
>>>> m=Matrix([[1,2],[3,4]])
>>>> m # the sstr form is printed
> Matrix([
> [1, 2],
> [3, 4]])
>>>> str(m)
> 'Matrix([[1, 2], [3, 4]])'
>>>> sstr(m)
> 'Matrix([\n[1, 2],\n[3, 4]])'
>>>> repr(m)
> 'Matrix([\n[1, 2],\n[3, 4]])'
>>>> srepr(m)
> 'Matrix([[Integer(1), Integer(2)], [Integer(3), Integer(4)]])'
>>>> S('''Matrix([
> ... [1, 2],
> ... [3, 4]])''')
> Matrix([
> [1, 2],
> [3, 4]])

+1 to adding newlines to the output. That makes a good compromise
IMHO. Does it also attempt to center things if the components are
different lengths?

Aaron Meurer

>
> /c
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To post to this group, send email to sympy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sympy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sympy?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to