Ask Your Question

Equivalence to Python -O flag ?

asked 2016-01-01 10:21:51 -0500

nguyenthanhvuh gravatar image

Hi, is there in Sage that's equivalent to running python with the flag -O, i.e., python -O ? This sets the __debug__ variable to 1 and remove all assertion code. I've tried sage -O and also look at sage -h but can't seem to find something like that.

edit retag flag offensive close merge delete


Sage console is based on Ipython. Does Ipython have such option?

vdelecroix gravatar imagevdelecroix ( 2016-01-01 10:26:56 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2016-01-02 09:35:42 -0500

tmonteil gravatar image

It seems doable as follows: from a terminal, type:

sage -sh

Then, from that shell, type:

python -O $(which sage-ipython)

Wait a bit, and it seems that you have a true Sage (with a preparser and so on), which understood the -O option of python:

sage: 2^2
sage: assert(2<1)
edit flag offensive delete link more

answered 2016-01-01 10:26:29 -0500

vdelecroix gravatar image

It seems that the answer is no. But you can do the following

$ sage -sh
(sage-sh)$ python -O
Python 2.7.10 (default, Dec 23 2015, 08:49:15) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import *     # long time
>>> R = PolynomialRing(ZZ, 'x')
>>> x = R.gen()
>>> (x**2 + 2*x + 1).factor()
(x + 1)^2

Be careful that Sage uses a preparser that is different from Python...

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


Asked: 2016-01-01 10:21:51 -0500

Seen: 255 times

Last updated: Jan 02 '16