Fusion 360 Script Engine Uses Python Version 3
One of the differences between Python 2 and 3 was changing print
from a statement to a function. This means a Python beginner like myself immediately runs into the breaking change trying to print "Hello World!" to the console. (print "Hello World!"
versus print("Hello World!")
) It sets the tone pretty clearly up front: when working with Python, developers need to know which version they're writing for.
Which is why I was very puzzled when I searched for this information in the Autodesk documentation and came up empty-handed. The most obvious place in my mind would be the "Python Specific Issues" page of the user's manual, but it wasn't mentioned there. Searching various other combinations of terms - on and off Autodesk's web site - failed to find a straightforward answer. Given the relatively young age of Fusion 360's Python scripting support, I would expect them to use Python 3 but I wanted confirmation.
Well, if I can't find it in documentation, there's always looking at the code itself. And a tiny baby step beyond the simple boilerplate script generated by Fusion 360. It's not quite printing "Hello World" but it's almost that simple.
First I imported the Python sys
module for querying system parameters.
import sys
Then I changed the boilerplate message box output string to include the version number.
ui.messageBox("We're running on Python " + str(sys.version_info.major), "Version detection")
Executing the script confirms the scripting engine is running Python 3.
Once the web search engines index this post, people who have this question in the future will know the answer just by reading the title of this post on the search results. They won't even need to click on the link to read this page.
(This really simple bit of code is almost not worth committing to Github... but it's a slow day so it was pushed up to be publicly available.)