Ask Your Question

Why show() is not working when we are using with print?

asked 2016-11-29 20:34:53 -0500

daviddgl gravatar image

updated 2016-11-29 20:49:03 -0500

Why show() is not working when we are using with print?

I have written a program to find a matrix as a result.

When I have finished and was tring to polish the output, I ended up the situation to use,

print " The matrix is ", show(A)

The output is just

The matrix is

its not giving the matrix.

if I use show() without print function, its giving the matrix.

How to fix this issue??

Thanks for helping..


As William Stein has given in his answer, I have used,


after print function. But it didnt help me.

I will give my subroutine, since if there is any bug in the code also give a bug in show() funciton.

for i in range(6):
    for j in range(6):
print "The compound matrix C2(A)=", '\n'
edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2016-11-29 20:56:39 -0500

kcrisman gravatar image

updated 2016-11-30 10:16:31 -0500

Note that in the question you reference, the show() functions are not in the same line as the print statements. The return value of show is what would go in the print statement, but what you want is what the show function does, which depends on whether you are in a notebook, etc. Embedded in a print statement I wouldn't know what to expect in general.

See this example in the Sage cell server to see what I mean:

a = 1
print a
print show(latex(a))

Note that this one does seem to do something for the print, but probably this depends on the frontend. Also notice the None printed at the end - that is what show returns.

Edit: For what you want to do, you might want something along the lines of this:

a = matrix(2,[1,2,3,4])
pretty_print(html("This is the matrix $%s$"%(latex(a))))

Sorry that it wasn't clear to me initially what you actually desired as output.

edit flag offensive delete link more


@kcrisman Is there anyway to achieve the requirement.. I wanted to show the output in matrix form not the output given by sage usually.

print "the matrix is"; show(A)

is working in one cell but not in the other..

I was not able to identify the bug(or mistake) in the front end.

daviddgl gravatar imagedaviddgl ( 2016-11-29 21:42:54 -0500 )edit

answered 2016-11-29 22:25:41 -0500

If you're in a notebook cell, why use print? Just show("The matrix is", A).

edit flag offensive delete link more

answered 2016-11-29 22:16:06 -0500

Probably you have a comma instead of a semi-colon.

Try replacing print " The matrix is ", show(A) by print " The matrix is "; show(A)?

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-11-29 20:34:53 -0500

Seen: 58 times

Last updated: Nov 30 '16