os.getcwd()
arcpy.env.workspace
import inspect, os scriptName = inspect.getfile( inspect.currentframe() ) scriptFolder = os.path.split(scriptName)[0]
# file test.py import sys import inspect def x(): print "inspect: ",repr(inspect.getfile(inspect.currentframe())) print "sys.argv[0]: ", repr(sys.argv[0]) x()
\Users\cprice>C:\Python27\ArcGIS10.1\python.exe test.py inspect: 'test.py' sys.argv[0]: 'test.py'
\Users\cprice>C:\Python27\ArcGIS10.1\python.exe Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import test inspect: 'test.py' sys.argv[0]: '' >>> test.x() inspect: 'test.py' sys.argv[0]: ''
>>> import test >>> test.__file__ 'test.py'
>>> import sys >>> import inspect >>> def x(): ... print "inspect: ",repr(inspect.getfile(inspect.currentframe())) ... print "sys.argv[0]: ", repr(sys.argv[0]) ... >>> x() inspect: '<stdin>' sys.argv[0]: '' >>>
>>> import sys >>> sys.version '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]' >>> sys.executable 'C:\\Python27\\ArcGIS10.1\\python.exe'
sys.version '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]' >>> sys.executable 'C:\\ArcGIS\\Desktop10.1\\bin\\ArcMap.exe'
def x(): import sys import inspect f = "inspect: %s" + chr(10) + "sys.argv[0]: %s" + chr(10) + \ "sys.version: %s" + chr(10) + "sys.executable: %s" return f % \ (repr(inspect.getfile(inspect.currentframe())), repr(sys.argv[0]),sys.version,sys.executable) -- Executing (Calculate Value): CalculateValue x() "def x():\n import sys\n import inspect\n f = "inspect: %s" + chr(10) + "sys.argv[0]: %s" + chr(10) + "sys.version: %s" + chr(10) + "sys.executable: %s" \n return f % \\n (repr(inspect.getfile(inspect.currentframe())), repr(sys.argv[0]),sys.version,sys.executable)\n" Variant Start Time: Wed Feb 06 10:37:05 2013 Value = inspect: '<string>' sys.argv[0]: '' sys.version: 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] sys.executable: C:\ArcGIS\Desktop10.1\bin\ArcMap.exe Succeeded at Wed Feb 06 10:37:05 2013 (Elapsed Time: 0.00 seconds)
os.path.split(inspect.getfile(inspect.currentframe()))[0]
Hello,I have some custom ArcGIS toolboxes containing script tools (v10.0 and v10.1) written in Python. Is there a way in Python to get the folder path of the script tool that is being executed?
import sys import os print sys.argv[0] print os.path.dirname(sys.argv[0])
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.