Ask Your Question
1

Python 3 print in Sage

asked 2017-09-12 18:40:04 +0200

tomcho gravatar image

This is a minor issue, but I've long migrated all my Python scripts to Py3, so I'm trying to write in Sage in the most Py3-compliant way possible, since we'll have Py3 support in a not-so-distant future according to the FAQs (frankly I'm a bit surprised that Py3 support haven't already happened, but, oh well).

Anyway, because of that I put from __future__ import print_function, division in the very first line of my init.sage.

If I type things interactively in the prompt, it works as it's supposed to:

sage: print('C_r' ,6)
C_r 6

However, if I run a script with load('my_script.sage') it prints things as if I was using Py2.

('C_r', 6)

Am I loading my scripts wrong? How can I get it to work for scripts too?

Cheers.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-09-13 08:30:09 +0200

eric_g gravatar image

You have either to add the line from __future__ import print_function at the top of the file my_script.sage or to use the magic command %load instead of load():

sage: %load my_script.sage
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-09-12 18:40:04 +0200

Seen: 427 times

Last updated: Sep 13 '17