Learning Python for Sage

i like this post (click again to cancel)
3
i dont like this post (click again to cancel)

Hi, I'm no expert in Python or Sage, but I want to learn Python specifically to help with Sage. I bought a book on Python programming and I'm trying out some of the stuff in Sage. But, some of it doesn't seem to work. So, I'm wondering... is this because Sage doesn't use Python 3 yet, or are there just some things with Python that don't work in Sage? If it's the second one, how can I know what's going to work and what's not? For example, in the book I have it says I should be able to do:

print("stuff stuff", end = " ")
print("stuff stuff")

and the effect is that instead of ending the print statement with "\n", it ends with a space so the second print statement prints on the same line. But, doing this in Sage 4.7 results in a syntax error, and it appears to not like the =.

Thanks

asked Sep 02 '11

G-Sage gravatar image G-Sage
301 2 17 30

3 Answers:

i like this answer (click again to cancel)
2
i dont like this answer (click again to cancel) G-Sage has selected this answer as correct

print("stuff stuff", end = " ") is certainly not valid in Python 2, and Sage is using Python 2, and switching is not going to happen soon.

Actually, print is not a function in Python 2, so it's not that it doesn't like '=', it doesn't like (), etc.

You can see few most common differences between Python versions 2 and 3 explained here: http://docs.python.org/release/3.0.1/whatsnew/3.0.html

link

posted Sep 02 '11

Dima gravatar image Dima
246 2 9
i like this answer (click again to cancel)
3
i dont like this answer (click again to cancel)

You might like looking at this book, which is the Python 2.x version of a very popular intro text.

link

posted Sep 02 '11

kcrisman gravatar image kcrisman
7802 20 78 170
i like this answer (click again to cancel)
3
i dont like this answer (click again to cancel)

Even in Python 2.7, you could import the print function from the future Python:

sage: from __future__ import print_function
sage: print("stuff stuff", end = " ")
stuff stuff sage: print("stuff stuff", end = " \n@\n")
stuff stuff 
@
sage:
link

posted Sep 05 '11

Simon King gravatar image Simon King
376 2 11

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
Login/Signup to Post

Question tools

1 follower

Tags:

Stats:

Asked: Sep 02 '11

Seen: 273 times

Last updated: Sep 05 '11

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.