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.Wed, 24 Apr 2019 19:14:49 +0200"from __future__ import print_function" fails on Sage scriptshttps://ask.sagemath.org/question/46342/from-__future__-import-print_function-fails-on-sage-scripts/Hello, Sage Community.
I am trying to use the "print" function in a .sage script, so I have added the line
from __future__ import print_function
as the first line to be included in my .sage file. Unfortunately, when running `sage test.sage`, Sage preparses the document and creates an auxiliary file "test.sage.py", which makes an import, then predefines some constants, and finally adds my preparsed code. As a consequence, the `from __future__ import print_function` is not the first line, and I get the following error message:
File "test.sage.py", line 6
from __future__ import print_function
SyntaxError: from __future__ imports must occur at the beginning of the file
Here is a MWE. The file "test.sage" containing:
from __future__ import print_function
print(1+1)
is preparsed to "test.sage.py" containing:
# This file was *autogenerated* from the file test.sage
from sage.all_cmdline import * # import sage library
_sage_const_1 = Integer(1)
from __future__ import print_function
print(_sage_const_1 +_sage_const_1 )
Of course, I could manually add this line to the .sage.py file and then execute it, but this could be tedious in my case for two reasons: 1. I have a lot of files which I have to modify and rerun every 15 minutes. 2. I also need this process to be automatic to be able to execute it with automatically generated script and even sageTeX.
Thanks in advance for your answers!dsejasWed, 24 Apr 2019 19:14:49 +0200https://ask.sagemath.org/question/46342/File imports for polynomial rings in sagehttps://ask.sagemath.org/question/7584/file-imports-for-polynomial-rings-in-sage/If i type in the following
R.<z1,z2> = PolynomialRing(GF(5),2,"z")
direclty to Sage it accepts it as a polynomial ring.
But if i place this in a .py file and load it from this Sage
eg `sage my.py` it gives me a syntax error.
I guess i need a module loaded for it to be detected, but which module and hence which command do i need to make Sage accept this ring.aeThu, 19 Aug 2010 11:41:02 +0200https://ask.sagemath.org/question/7584/