Ask Your Question
1

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

asked 4 years ago

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!

Preview: (hide)

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 ( 4 years ago )

And there is no fully automatic way.

FrédéricC gravatar imageFrédéricC ( 4 years ago )

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

FrédéricC gravatar imageFrédéricC ( 4 years ago )

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 ( 4 years ago )

1 Answer

Sort by » oldest newest most voted
3

answered 4 years ago

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.)

Preview: (hide)
link

Comments

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

Bark gravatar imageBark ( 4 years ago )

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: 4 years ago

Seen: 378 times

Last updated: Sep 12 '20