ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 02 Jan 2016 16:35:42 +0100Equivalence to Python -O flag ?https://ask.sagemath.org/question/31959/equivalence-to-python-o-flag/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, Fri, 01 Jan 2016 17:21:51 +0100https://ask.sagemath.org/question/31959/equivalence-to-python-o-flag/Comment by vdelecroix for <p>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. <br/>
Thanks, </p>
https://ask.sagemath.org/question/31959/equivalence-to-python-o-flag/?comment=31962#post-id-31962Sage console is based on Ipython. Does Ipython have such option?Fri, 01 Jan 2016 17:26:56 +0100https://ask.sagemath.org/question/31959/equivalence-to-python-o-flag/?comment=31962#post-id-31962Answer by vdelecroix for <p>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. <br/>
Thanks, </p>
https://ask.sagemath.org/question/31959/equivalence-to-python-o-flag/?answer=31961#post-id-31961It 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...Fri, 01 Jan 2016 17:26:29 +0100https://ask.sagemath.org/question/31959/equivalence-to-python-o-flag/?answer=31961#post-id-31961Answer by tmonteil for <p>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. <br/>
Thanks, </p>
https://ask.sagemath.org/question/31959/equivalence-to-python-o-flag/?answer=31986#post-id-31986It 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>
Sat, 02 Jan 2016 16:35:42 +0100https://ask.sagemath.org/question/31959/equivalence-to-python-o-flag/?answer=31986#post-id-31986