Ask Your Question
1

Error on %attach for import __future__

asked 2016-06-28 03:52:31 -0600

temp_user gravatar image

updated 2016-06-28 04:16:21 -0600

tmonteil gravatar image

Hi,

using sagemath version 7.0 and 7.2, I tried to attach a file with %attach file.sage. The first line in the file is

from __future__ import division

which results in

sage: %attach file.sage
File "/home/user/.sage/temp/host/25397/file.sageTVxNnD.py", line 6
from __future__ import division
SyntaxError: from __future__ imports must occur at the beginning of the file

The error message is modified to hide user/host/... info

There is a older question on ask.sagemath /question/9071/future-import-fails-in-loading-external-cython-file/ which is addressing the same problem from 2012 on SageMath version 5.0 but there is no answer. I'm baffled that the error occurs in line 6 since the import statement is in the first line in the attached file.

Any ideas how to fix this?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-06-28 04:07:04 -0600

tmonteil gravatar image

I am not sure about the details of %attach that probably do something before interpreting the content of the file. A workaround is to use %load instead.

edit flag offensive delete link more

Comments

That's bad since it first takes a long while to load a bigger script and second there is no automatic reloading if I read the doc correctly. But it'll have to do now.

temp_user gravatar imagetemp_user ( 2016-06-28 05:38:13 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-06-28 03:52:31 -0600

Seen: 33 times

Last updated: Jun 28 '16