<?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 Re: Python:  Using sys.argv[1] in Update Cursor in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/python-nbsp-using-sys-argv-1-in-update-cursor/m-p/110540#M3780</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Jason:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So is getattr() and setattr() preferable to the esri cursor methods of getvalue() and setvalue(). That is to say, are they faster or for some other reason better? Regardless, seems pretty cool!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 10 Aug 2010 16:56:03 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2010-08-10T16:56:03Z</dc:date>
    <item>
      <title>Python:  Using sys.argv[1] in Update Cursor</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-nbsp-using-sys-argv-1-in-update-cursor/m-p/110536#M3776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would like to create tool for multiple users with multiple datasets from multiple sources. Each dataset contains the same data, it's just stored differently, mostly just different field names and input locations etc... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it possible to insert a variable into an Update Cursor to give the tool more flexibility with multiple users? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
InAge = sys.argv[1]

rows = gp.UpdateCursor("c:\temp\test.dbf")
row = rows.Next()
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.InAge == 25:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.Range = "Mid"

&lt;/PRE&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Will InAge work as a variable? Or will the cursor look for a field called "InAge" ? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is this even possible ? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:01:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-nbsp-using-sys-argv-1-in-update-cursor/m-p/110536#M3776</guid>
      <dc:creator>JamesHood</dc:creator>
      <dc:date>2021-12-12T16:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python:  Using sys.argv[1] in Update Cursor</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-nbsp-using-sys-argv-1-in-update-cursor/m-p/110537#M3777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Use the getattr builtin:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;InAge = gp.GetParameterAsText(0)

rows = gp.UpdateCursor("c:\temp\test.dbf")
row = rows.Next()
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if getattr(row, InAge) == 25:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.Range = "Mid"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:38:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-nbsp-using-sys-argv-1-in-update-cursor/m-p/110537#M3777</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2021-12-11T06:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: Python:  Using sys.argv[1] in Update Cursor</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-nbsp-using-sys-argv-1-in-update-cursor/m-p/110538#M3778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I ran a test on that and it works like a charm!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to take it a step further though and I found that I can't use the getattr ( , ) function to allow the user to define what the input field name will be.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
InAge = gp.GetParameterAsText(0)
OutField = gp.GetParameterAsText(1)

rows = gp.UpdateCursor("c:\temp\test.dbf")
row = rows.Next()
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if getattr(row, InAge) == 25:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getattr(row, OutField) = "Mid" #&amp;lt;-- DOES NOT WORK: RETURNS SYNTAX ERROR AT THIS LINE
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #row.Range = "Mid"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"ERROR: Failed to check - syntax error - can't assign to function call (test.py, line 23)"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I guess the reason it fails is this:&amp;nbsp; In the if line " if getattr(row, InAge) == 25:"&amp;nbsp; we are assigning a user value to the variable then asking IF it equals 25, do the following: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then in the following, we assigning another user value to the variable to be the FieldName,&amp;nbsp; but then immediately trying to re-assign a new value, changing the FieldName, to the input value for that field.&amp;nbsp; Then python gets confused and screwy.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unless there is some kind of list or tuple or something that would allow the storage of more than one value in the attribute to be used in this circumstance,&amp;nbsp; I don't know if it would ever work...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks jscheirer,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- James&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:39:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-nbsp-using-sys-argv-1-in-update-cursor/m-p/110538#M3778</guid>
      <dc:creator>JamesHood</dc:creator>
      <dc:date>2021-12-11T06:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: Python:  Using sys.argv[1] in Update Cursor</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-nbsp-using-sys-argv-1-in-update-cursor/m-p/110539#M3779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Use setattr:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;setattr(row, OutField, "Mid")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Aug 2010 16:13:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-nbsp-using-sys-argv-1-in-update-cursor/m-p/110539#M3779</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2010-08-10T16:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python:  Using sys.argv[1] in Update Cursor</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-nbsp-using-sys-argv-1-in-update-cursor/m-p/110540#M3780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Jason:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So is getattr() and setattr() preferable to the esri cursor methods of getvalue() and setvalue(). That is to say, are they faster or for some other reason better? Regardless, seems pretty cool!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Aug 2010 16:56:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-nbsp-using-sys-argv-1-in-update-cursor/m-p/110540#M3780</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-08-10T16:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python:  Using sys.argv[1] in Update Cursor</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-nbsp-using-sys-argv-1-in-update-cursor/m-p/110541#M3781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Functionally they are the same, just getattr and setattr will work on &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;any&lt;/SPAN&gt;&lt;SPAN&gt; Python object, not just row objects.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Aug 2010 00:49:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-nbsp-using-sys-argv-1-in-update-cursor/m-p/110541#M3781</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2010-08-11T00:49:26Z</dc:date>
    </item>
  </channel>
</rss>

