Ask Your Question
1

Convert sage code from v8.1 to work in v9.1

asked 2020-09-12 04:29:51 +0100

Bark gravatar image

Hi all,

I have a .sage file that works with Sage v8.1, however, it does not run with Sage v9.1. It seems the issues are the same issues that occur with Python2 vs Python3 syntax i.e. print statement syntax is print 'statement' vs print('statement')

Rather than go through line by line and find each difference, is there a way to convert the file to make it run for Sage 9.0 and later?

Any assistance would be appreciated!

edit retag flag offensive close merge delete

Comments

Some useful tools are flycheck, pyflakes, flake8, pycodestyle : they allow to find the places needing care.

See also https://wiki.sagemath.org/Python3-Switch and its sub-pages

FrédéricC gravatar imageFrédéricC ( 2020-09-12 08:07:14 +0100 )edit

And there is no fully automatic way.

FrédéricC gravatar imageFrédéricC ( 2020-09-12 08:08:58 +0100 )edit

And all these tools are for .py files, of course.

FrédéricC gravatar imageFrédéricC ( 2020-09-12 09:02:11 +0100 )edit

So far I've always ported code by hand but if your .sage file is public or if you email it to me I can try some of the tools on it.

slelievre gravatar imageslelievre ( 2020-09-12 12:24:24 +0100 )edit

1 Answer

Sort by » oldest newest most voted
3

answered 2020-09-12 18:18:40 +0100

There is a script 2to3 that converts Python 2 code to Python 3 code, in addition to the tools mentioned by @FrédéricC. Try running that on the file. (It is intended for .py files, but it may also work on a .sage file. Or you can do sage --preparse file.sage to produce file.sage.py, and then run 2to3 on that.)

edit flag offensive delete link more

Comments

Thank you! This is precisely what I was looking for!

Bark gravatar imageBark ( 2020-09-13 01:06:08 +0100 )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: 2020-09-12 04:29:51 +0100

Seen: 346 times

Last updated: Sep 12 '20