Testing and consecutive spaces in output

42 views
Skip to first unread message

Jori Mäntysalo

unread,
May 23, 2016, 3:11:59 AM5/23/16
to sage-...@googlegroups.com
I just saw a ticket where

print "x = ", x

was changed to

print("x = {}".format(x)

i.e. for example "x = 42" is changed to "x = 42". But testing went fine.
So is there some logic that slightly modifies expected output before
testing? If so, what else it does than sqeeze consecutive spaces?

--
Jori Mäntysalo

Travis Scrimshaw

unread,
May 23, 2016, 3:20:37 AM5/23/16
to sage-devel
Hey Jori,
   As I understand it, extra whitespace is ignored by the doctester.

Best,
Travis

Jori Mäntysalo

unread,
May 23, 2016, 3:32:12 AM5/23/16
to sage-devel
On Mon, 23 May 2016, Travis Scrimshaw wrote:

> As I understand it, extra whitespace is ignored by the doctester.

OK. Sounds mostly reasonable, but means of course that nice printing of
matrices can not be tested easily.

--
Jori Mäntysalo

John Cremona

unread,
May 23, 2016, 4:47:48 AM5/23/16
to SAGE devel
Are we not allowed to use

print("x = %s" % x)

any more?

John

William Stein

unread,
May 23, 2016, 4:57:26 AM5/23/16
to sage-devel
On Mon, May 23, 2016 at 1:47 AM, John Cremona <john.c...@gmail.com> wrote:
> Are we not allowed to use
>
> print("x = %s" % x)
>
> any more?

It works fine in python3.

$ python3
Python 3.5.1+ (default, Mar 30 2016, 22:46:26)
[GCC 5.3.1 20160330] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("x = %s" % 'john')
x = john

However, the new (?) format method on strings does in general tend to
lead to more readable and maintainable code. At least that was my
experience during the last three days, during which I wrote a large
amount of Python3 code.

--
William (http://wstein.org)

John Cremona

unread,
May 23, 2016, 5:31:22 AM5/23/16
to SAGE devel
Thanks for the clarification. I suppose that Sage library code does
not have many print statements anyway except for debugging (and now I
am sure that someone will prove me worng with an exact count!). I was
thinking more of other python code I write (for otherprojects such as
LMFDB) which should also be future-proofed.

John

>
> --
> William (http://wstein.org)
>
> --
> You received this message because you are subscribed to the Google Groups "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
> To post to this group, send email to sage-...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.

Jori Mäntysalo

unread,
May 23, 2016, 5:38:28 AM5/23/16
to SAGE devel
On Mon, 23 May 2016, John Cremona wrote:

> Are we not allowed to use
>
> print("x = %s" % x)
>
> any more?

https://docs.python.org/release/3.1.5/library/stdtypes.html#old-string-formatting-operations
says "The formatting operations described here are obsolete and may go
away in future versions of Python."

Hence I guess no new code should use percent sign any more. But what comes
to changing old print statements, I think it is OK to just make them
Python3-compliant.

--
Jori Mäntysalo

Nils Bruin

unread,
May 23, 2016, 1:34:54 PM5/23/16
to sage-devel
On Monday, May 23, 2016 at 2:38:28 AM UTC-7, Jori Mäntysalo wrote:
https://docs.python.org/release/3.1.5/library/stdtypes.html#old-string-formatting-operations
says "The formatting operations described here are obsolete and may go
away in future versions of Python."

...and a few versions later it's clear removal is not going to happen in the coming few decades.
 
Reply all
Reply to author
Forward
0 new messages