First time here? Check out the FAQ!

Ask Your Question
1

Python 3 print in Sage

asked 7 years ago

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 7 years ago

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
Preview: (hide)
link

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

Seen: 743 times

Last updated: Sep 13 '17