ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 13 Sep 2017 01:30:09 -0500Python 3 print in Sagehttp://ask.sagemath.org/question/38805/python-3-print-in-sage/ 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.Tue, 12 Sep 2017 11:40:04 -0500http://ask.sagemath.org/question/38805/python-3-print-in-sage/Answer by eric_g for <p>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).</p>
<p>Anyway, because of that I put <code>from __future__ import print_function, division</code> in the very first line of my <code>init.sage</code>.</p>
<p>If I type things interactively in the prompt, it works as it's supposed to:</p>
<pre><code>sage: print('C_r' ,6)
C_r 6
</code></pre>
<p>However, if I run a script with <code>load('my_script.sage')</code> it prints things as if I was using Py2.</p>
<pre><code>('C_r', 6)
</code></pre>
<p>Am I loading my scripts wrong? How can I get it to work for scripts too?</p>
<p>Cheers.</p>
http://ask.sagemath.org/question/38805/python-3-print-in-sage/?answer=38809#post-id-38809You 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
Wed, 13 Sep 2017 01:30:09 -0500http://ask.sagemath.org/question/38805/python-3-print-in-sage/?answer=38809#post-id-38809