Changing Python version via script


#1

Just curious, Is there a way to the change the python version from the script editor?


#2

Hi @aquaphoenix17,

It would be nice to be able to do that.

If you would like to use the Codecademy script editor to run a program in a Python 3 interpreter, it probably will not work. However, you can execute a Python 3 program from a Python 2 program on your own system if you have both Python versions installed.

  • Create two files as follows, naming them based on the comments.
  • Run the first file in Python 2.x

# Execute_Python_3_Hello.py
import os
print("Hello World from Python 2.7!")
print("Let's execute a Python 3.6 program!")
os.system("Python3.6 Hello_World_Python_3.py")

The above file will execute the file below ...

# Hello_World_Python_3.py
print("Hello World from Python 3.6!")

Interactive session in Terminal ...

$ python2.7 Execute_Python_3_Hello.py
Hello World from Python 2.7!
Let's execute a Python 3.6 program!
Hello World from Python 3.6!
$

However, that's probably not what you hoped to do.