Ask Your Question
2

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.
Thanks,

edit retag flag offensive close merge delete

Comments

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
0

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
4
sage: assert(2<1)
<nothing>
edit flag offensive delete link more
0

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

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

Stats

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

Seen: 248 times

Last updated: Jan 02 '16