Sourcing a Python Script


Hi everyone! I’m a beginner in python and I’m having a bit of trouble running a script through the command flag of a menuItem. Right now i’m using execfile, adding the directory path of my script and adding the name of my .py script but it returns this error: Error: IOError: file line 1: 2

Here is an example of the script I’m running that creates the menu parented to MayaWindow:

import maya.cmds as cmds
import maya.mel as mel

myScriptDirectory= cmds.internalVar(userScriptDir= True)
myPythonVariable= mel.eval("$tempMelVar= $gMainWindow")

if“testMenu”, exists= True):“testMenu”, edit= True, dai= True)
cmds.setParent(myPythonVariable)“testMenu”, l= “Test Tool”, p= “MayaWindow”, to= True)

cmds.setParent(“testMenu”, m= True)

cmds.menuItem(l= “Misc”, sm= True, to= True)
cmds.menuItem(l= “HelloPrinter”, c= (“execfile(”" + myScriptDirectory + “”)"))
cmds.setParent("…", m= True)

And here is the script I’m trying to run remotely (saved with the name under the Maya scripts directory):

print “hello world!”