<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Script seems to function differently when run as part of a geoprocessing service in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/script-seems-to-function-differently-when-run-as/m-p/308700#M24020</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a model which in the incorporates a python script. Everything in my model works perfectly when I run it in the desktop environment. When I run the model as a geoprocessing service everything works, but my results are strange.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Basically my model takes user input that selects a county, calculates a field on that row. Then exports that field with all the rows as a text file. This is the input parameter for my script. My script performs matrix algebra on that row, then exports the results as a text file called product. This is the output parameter of my script. My model takes that text file, makes it into a dbf and joins it back to the original shapefile. Something is going wrong somewhere though when run as a service because the values seem to get joined back to the wrong rows, even though they get joined to the correct rows when run in the desktop environment. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure if the problem is in my script, but I was wondering if it had something to do with not using the arcgis server scratchworkspace in my script as I do in the model?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;from __future__ import with_statement 
from numpy import *
import arcpy
import time
import sys, string, os, arcgisscripting, shutil
gp = arcgisscripting.create(9.3)
from arcpy import env

tablePath = gp.GetParameterAsText(0)


#Load durbin.txt file
durbin= loadtxt("C:\\inetpub\\wwwroot\\REIS\\assets\\durbin_edit.txt")
print durbin
print"durbin loaded"
#load all columns except the first column which is the poly ids for the counties
durbin_cut=durbin[:,1:]
print durbin_cut
print"durbin columns selected"
#Load output of model, which includes 2 columns for x and y, impossible not to include
delta= loadtxt (tablePath)
print delta
print "delta loaded"
#Select only results column, exclude x and y coordinate columns from output
delta_cut = delta[:, 2:]
print delta_cut
print "column selected"
#Multiply using matrix algebra durbin_cut by delta_cut
product= dot(durbin_cut,delta_cut)
print product
print "calculated"

#Get current time for file names
date1=time.strftime("%d%b%y%H%M%S_")
print date1


#make a text file from array with header and product
dateproduct=date1 + "_product.txt"
print dateproduct
textfilename= "C:\Users\WinSSHD_VirtualUsers\Downloads\WebGIS project\Counties00_08_web\scratch\out" + dateproduct
print textfilename

product.tofile (textfilename, sep='\n', format="%e")
print "file created"
#open text file
with open(textfilename, "r+") as f:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; old = f.read() # read everything in the file
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.seek(0) # rewind
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write("value\n" + old) # write the new line before everything

print "all done"

#Set output parameter
arcpy.SetParameterAsText(1, textfilename)

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any insight would be greatly appreciated!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 09 Nov 2011 00:38:19 GMT</pubDate>
    <dc:creator>MelissaTalley</dc:creator>
    <dc:date>2011-11-09T00:38:19Z</dc:date>
    <item>
      <title>Script seems to function differently when run as part of a geoprocessing service</title>
      <link>https://community.esri.com/t5/python-questions/script-seems-to-function-differently-when-run-as/m-p/308700#M24020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a model which in the incorporates a python script. Everything in my model works perfectly when I run it in the desktop environment. When I run the model as a geoprocessing service everything works, but my results are strange.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Basically my model takes user input that selects a county, calculates a field on that row. Then exports that field with all the rows as a text file. This is the input parameter for my script. My script performs matrix algebra on that row, then exports the results as a text file called product. This is the output parameter of my script. My model takes that text file, makes it into a dbf and joins it back to the original shapefile. Something is going wrong somewhere though when run as a service because the values seem to get joined back to the wrong rows, even though they get joined to the correct rows when run in the desktop environment. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure if the problem is in my script, but I was wondering if it had something to do with not using the arcgis server scratchworkspace in my script as I do in the model?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;from __future__ import with_statement 
from numpy import *
import arcpy
import time
import sys, string, os, arcgisscripting, shutil
gp = arcgisscripting.create(9.3)
from arcpy import env

tablePath = gp.GetParameterAsText(0)


#Load durbin.txt file
durbin= loadtxt("C:\\inetpub\\wwwroot\\REIS\\assets\\durbin_edit.txt")
print durbin
print"durbin loaded"
#load all columns except the first column which is the poly ids for the counties
durbin_cut=durbin[:,1:]
print durbin_cut
print"durbin columns selected"
#Load output of model, which includes 2 columns for x and y, impossible not to include
delta= loadtxt (tablePath)
print delta
print "delta loaded"
#Select only results column, exclude x and y coordinate columns from output
delta_cut = delta[:, 2:]
print delta_cut
print "column selected"
#Multiply using matrix algebra durbin_cut by delta_cut
product= dot(durbin_cut,delta_cut)
print product
print "calculated"

#Get current time for file names
date1=time.strftime("%d%b%y%H%M%S_")
print date1


#make a text file from array with header and product
dateproduct=date1 + "_product.txt"
print dateproduct
textfilename= "C:\Users\WinSSHD_VirtualUsers\Downloads\WebGIS project\Counties00_08_web\scratch\out" + dateproduct
print textfilename

product.tofile (textfilename, sep='\n', format="%e")
print "file created"
#open text file
with open(textfilename, "r+") as f:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; old = f.read() # read everything in the file
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.seek(0) # rewind
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write("value\n" + old) # write the new line before everything

print "all done"

#Set output parameter
arcpy.SetParameterAsText(1, textfilename)

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any insight would be greatly appreciated!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Nov 2011 00:38:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-seems-to-function-differently-when-run-as/m-p/308700#M24020</guid>
      <dc:creator>MelissaTalley</dc:creator>
      <dc:date>2011-11-09T00:38:19Z</dc:date>
    </item>
  </channel>
</rss>

