Forum Archive

Can you make a script run in Python 2 with an argument?

JSOgaard

Is there a way of making a script run in Python 2 with an argument in the Run Options?
If not, is there another way of making a specific script run in Python 2 when Python 3 is my default setting?

cvp

@JSOgaard you can start a script in Python 2 with

from objc_util import * 
import os
app = 'myfolder/myapp.py'
path = os.path.expanduser('~/Documents/'+app)
arg = ['1','2']
I2=ObjCClass('PYK2Interpreter').sharedInterpreter()
# run a script like in wrench menu (path, args, reset env yes/no)
I2.runScriptAtPath_argv_resetEnvironment_(path, arg, True)
cvp

@JSOgaard a script can run in Python if 1st line is

#!python2
cvp

@JSOgaard I don't remember for the App Store version but the beta provides this when you long press the run button