ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 20 Apr 2019 22:10:21 -0500REPL-like outputhttps://ask.sagemath.org/question/46294/repl-like-output/Hello, Sage Community.
If I run the sage REPL in a terminal, and execute something like
for i in range(4):
print(i^2)
then we all know that Sage prints
0
1
4
9
In this case, I could create a class to intercept standard output to a variable, like:
class verboseBuffer:
def __init__(self):
self.buffer = ''
def write(self, s):
self.buffer += s
Then I just make
_verbOut_ = verboseBuffer()
sys.stdout = _verbOut_
and if I run the first chunk of code, then the integers will be stored in `_verbOut_.buffer`, instead of being printed to standard output as before. I finally can do
sys.stdout = sys.__stdout__
print(_verbOut_.buffer)
and this prints the contents of `_verbOut_.buffer`, i.e., the list at the beginning.
Now consider the same loop without the `print`:
for i in range(4):
i^2
Executed in the REPL, Sage will print exactly the same as before (even if I haven't specified to `print`), and I could do the same thing to redirect the standard output to a variable.
Now, on the other hand, I have a huge file for which I would like to print everything in the same way it is printed in the REPL. I can't add `print` to every single part of the file, so I have tried to redirect output to a variable as before, and print it in the last line. The problem is that, things like the last chunk of code, without an explicit `print` won't be stored in `_verbOut_.buffer` at the end of the execution.
My questions are:
1. Why does the Sage REPL prints all computations not assigned to a variable, like the `i^2` in the loop, but that doesn't happen if the code is in a file?
2. How can I obtain a REPL-like output without having to add `print` to everything in my long file?dsejasSat, 20 Apr 2019 22:10:21 -0500https://ask.sagemath.org/question/46294/How do i change the x and y steps of an plot?https://ask.sagemath.org/question/44237/how-do-i-change-the-x-and-y-steps-of-an-plot/So i want a coordinate system that has different steps for example.
i have this
plot(-1/2*x+1,(x,-2, 8), rgbcolor=('#00c147')) #h1
how can i change the steps at the x-axis, at the moment it prints the numbers at {-2,2,4,6,8}
and i want it to be {-2,-1,0,1,2,3,4,5,6,7,8}
how can i customize those steps at the x and y-axis and how can i make it printable that for example 1 step has the distance of 0.5cm+0.5cm on a plain A4 paper.
at the moment 1 is at 1.5cm, 2 at 3cm EDIT:(nvm the printer had the wrong settings)neorySun, 11 Nov 2018 08:03:26 -0600https://ask.sagemath.org/question/44237/Is it possible to get fortran code for an expression?https://ask.sagemath.org/question/41525/is-it-possible-to-get-fortran-code-for-an-expression/Hello, is it possible to get the fortran code for expressions in SageMath?
Here's what I mean:
sage: var('a b x y')
( a, b, x, y )
sage: eq = x^a + 3/2*y^b
sage: get_fortran(eq)
x**a + 3.0/2.0*y**b
Right now the best I can do as a workaround is:
sage: eq.__str__().replace('^', '**')
x**a + 3/2*y**b
but the numbers appear as integers, which makes the division be performed as integer division in Fortran, which forces me to manually change that. Is there a function I can use to get what I want?
Cheers
tomchoTue, 13 Mar 2018 20:55:01 -0500https://ask.sagemath.org/question/41525/Printing variable namehttps://ask.sagemath.org/question/40862/printing-variable-name/ How would I return a variable name in a function. E.g. If I have the function:
def mul(a,b):
return a*b
a = mul(1,2); a
b = mul(1,3); b
c = mul(1,4); c
This would return:
2
3
4
I would like it to return:
a = 2
b = 3
c = 4
How would I do this?pytonnoobMon, 29 Jan 2018 12:05:32 -0600https://ask.sagemath.org/question/40862/If I return a list from a function that is more than 26 elements, the list goes verticalhttps://ask.sagemath.org/question/37477/if-i-return-a-list-from-a-function-that-is-more-than-26-elements-the-list-goes-vertical/If I return a list from a function that is more than 26 elements, the list goes vertical instead of horizontal even if I turn pretty printing off. Is this normal, and can I turn it off? I'm just returning the list, not using print explicitly. i.e.
With range 26 in the testfunc it shows a horizontal list, but if I increase that to 27 it goes vertical:
def tester():
v=[]
for i in range(26):
v.append(3)
return vcybervigilanteSun, 30 Apr 2017 19:21:50 -0500https://ask.sagemath.org/question/37477/How to print equations and numbers on a single line:https://ask.sagemath.org/question/36183/how-to-print-equations-and-numbers-on-a-single-line/I am trying to print a string, an equation and a number on the same line using the following form:
B=var('B')
fce=var('fce', latex_name='f_{ce}')
fce=2.80e6 * B
values={B:1.0e5}
print "Electron Gyrofrequency=", show(fce) , "= %0.5e" % fce.substitute(values)
However the output does not show as a single line. Any help would be appreciated.lookin03820Wed, 04 Jan 2017 13:17:37 -0600https://ask.sagemath.org/question/36183/IPython/Jupyter extensionshttps://ask.sagemath.org/question/26586/ipythonjupyter-extensions/I would like to be able to print code objects in a markdown cell without having to completely regenerate them in markdown code or copy/paste values. Would it be possible to install the [IPython notebook extensions](https://github.com/ipython-contrib/IPython-notebook-extensions) on the Sage Math Cloud?
I've made a public notebook [here](https://cloud.sagemath.com/projects/b8cc072a-0bd7-46df-bed6-4d857c87721b/files/Pretty%20printing.html) so that anyone can see exactly what my problem is. It's a fairly thorough description, but it boils down to wanting to print values with pretty units. I would be willing to allow others to edit the notebook to fiddle around with fixing it.wlp2Sat, 18 Apr 2015 01:29:48 -0500https://ask.sagemath.org/question/26586/Print out notebook worksheethttps://ask.sagemath.org/question/10828/print-out-notebook-worksheet/Hi all.
When I try to click "Print" button on Sage Notebook Worksheet in Firefox, it just opens another browser window with HTML view of the Worksheet. Is there anyway I can send it to a printer or get a PDF file instead of HTML?amit112amitThu, 12 Dec 2013 11:28:34 -0600https://ask.sagemath.org/question/10828/Missing Jmol Images when printinghttps://ask.sagemath.org/question/8357/missing-jmol-images-when-printing/When I attempt to print a notebook worksheet using either Safari or Chrome containing four plot3D-Jmol images, several are black (not displayed). Is this a memory problem? Is there
a way to force the plots to be static images instead of live JMol applets.
Sorry to say this but if this is not fixed I won't be able to use Sage for undergraduate teaching as
I must be able to post PDF's of examples easily!
Prof. Adam Hausknecht
Department of Mathematics
UMass DartmouthahausknechtTue, 04 Oct 2011 17:11:17 -0500https://ask.sagemath.org/question/8357/