Get the __file__ in Maya

When I run this script:

`import os.path

try:
approot = os.path.dirname(os.path.abspath(file))
except NameError:
import sys
approot = os.path.dirname(os.path.abspath(sys.argv[0]))

print approot`

through a line like this in a script editor:
execfile(“C:\test.py”)#the path to the script

I always get ‘C:\Program Files\Autodesk\Maya2020\bin’ not the the path to the script.
Why?

This topic was automatically closed after 93 days. New replies are no longer allowed.