Python Script With Relative Paths Published to Server

Discussion created by shaun_weston-eagle-co-nz-esridist on Jul 24, 2012
Latest reply on Jul 26, 2012 by alanrussian
I've got a python script that I have published to server that worked fine in 10.0, but for some reason I'm having trouble with it in 10.1 and it's because I'm using os.path to work out relative paths. So here's is the code I've got:

scriptPath = sys.path[0]
propertyReportFolder = os.path.dirname(scriptPath)
PropertyReportFeatureClass = os.path.join(propertyReportFolder, "Data.gdb\Property_Report")
PropertyReportFeatureClassSelected = os.path.join(propertyReportFolder, "Data.gdb\Property_Selected")

Then I reference these feature classes later on, now this works fine in Desktop, but when I publish it to server it instantly fails. When I change the above code to the following:

propertyReportFolder = "D:\\Data\\temp\\Property Report"
PropertyReportFeatureClass = "D:\\Data\\temp\\Property Report\Data.gdb\\Property_Report"
PropertyReportFeatureClassSelected = "D:\\Data\\temp\\Property Report\Data.gdb\\Property_Selected"

It works fine.

So, I am having to set the path to the files through the code rather than having the python script work it out. Any ideas on why it instantly fails when I run it as a gp service? I have this setup on seperate machine in ArcGIS Server 10.0 and it works fine.