<?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 Trouble with soft coding and updating row values in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/trouble-with-soft-coding-and-updating-row-values/m-p/488575#M38171</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have developed a hard coded script that removes more than one consecutive white space from a field in a table that works fine. However when I have now transitioned into creating a soft-coded version it does not work properly and populates the affectedField with whatever string the user supplies for the second GetParameterAsText arguement. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It seems to me that the script only views my supplied agruement as a string in the re.sub portion of the script. How can I get the re.sub to view the supplied arguement not as a string but more as a pointer to the correct fieldName.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any insight you can give me on this would be great. Thank you! Here is a sample of my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
#get necessary libraries for script
import arcpy, os, re, sys

#set up workspace
arcpy.env.overwriteOutput = True

try:
#arcpy.env.workspace = arcpy.GetParameter(0)
&amp;nbsp; fc = arcpy.GetParameterAsText(0)
&amp;nbsp; fieldName = arcpy.GetParameterAsText(1)
&amp;nbsp; affectedField = 'row.' + fieldName
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
#Open Search Cursor for table
&amp;nbsp; rows = arcpy.UpdateCursor(fc,'', '', fieldName)
&amp;nbsp; row = rows.next()

&amp;nbsp; desc = arcpy.Describe(fc)

&amp;nbsp; while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; newValue = re.sub('\s+' , ' ', row.CtySt)&amp;nbsp; #this one works but is hard-coded
&amp;nbsp;&amp;nbsp;&amp;nbsp; #newValue = re.sub('\s+' , ' ', affectedField) #this one does not work but is soft-coded...&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(fieldName, newValue)
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()

&amp;nbsp; del row, rows

#Report a success message
&amp;nbsp; arcpy.AddMessage("The unwanted blank spaces have been removed.")

except:
&amp;nbsp; #Report an error message
&amp;nbsp; arcpy.AddError("Could not complete the process.")

&amp;nbsp; #Report any error messages that ESRI generates
&amp;nbsp; arcpy.AddMessage(arcpy.GetMessages())
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Jul 2012 15:14:21 GMT</pubDate>
    <dc:creator>JamesHensleigh</dc:creator>
    <dc:date>2012-07-06T15:14:21Z</dc:date>
    <item>
      <title>Trouble with soft coding and updating row values</title>
      <link>https://community.esri.com/t5/python-questions/trouble-with-soft-coding-and-updating-row-values/m-p/488575#M38171</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have developed a hard coded script that removes more than one consecutive white space from a field in a table that works fine. However when I have now transitioned into creating a soft-coded version it does not work properly and populates the affectedField with whatever string the user supplies for the second GetParameterAsText arguement. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It seems to me that the script only views my supplied agruement as a string in the re.sub portion of the script. How can I get the re.sub to view the supplied arguement not as a string but more as a pointer to the correct fieldName.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any insight you can give me on this would be great. Thank you! Here is a sample of my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
#get necessary libraries for script
import arcpy, os, re, sys

#set up workspace
arcpy.env.overwriteOutput = True

try:
#arcpy.env.workspace = arcpy.GetParameter(0)
&amp;nbsp; fc = arcpy.GetParameterAsText(0)
&amp;nbsp; fieldName = arcpy.GetParameterAsText(1)
&amp;nbsp; affectedField = 'row.' + fieldName
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
#Open Search Cursor for table
&amp;nbsp; rows = arcpy.UpdateCursor(fc,'', '', fieldName)
&amp;nbsp; row = rows.next()

&amp;nbsp; desc = arcpy.Describe(fc)

&amp;nbsp; while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; newValue = re.sub('\s+' , ' ', row.CtySt)&amp;nbsp; #this one works but is hard-coded
&amp;nbsp;&amp;nbsp;&amp;nbsp; #newValue = re.sub('\s+' , ' ', affectedField) #this one does not work but is soft-coded...&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(fieldName, newValue)
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()

&amp;nbsp; del row, rows

#Report a success message
&amp;nbsp; arcpy.AddMessage("The unwanted blank spaces have been removed.")

except:
&amp;nbsp; #Report an error message
&amp;nbsp; arcpy.AddError("Could not complete the process.")

&amp;nbsp; #Report any error messages that ESRI generates
&amp;nbsp; arcpy.AddMessage(arcpy.GetMessages())
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2012 15:14:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-with-soft-coding-and-updating-row-values/m-p/488575#M38171</guid>
      <dc:creator>JamesHensleigh</dc:creator>
      <dc:date>2012-07-06T15:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with soft coding and updating row values</title>
      <link>https://community.esri.com/t5/python-questions/trouble-with-soft-coding-and-updating-row-values/m-p/488576#M38172</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;try this&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; #newValue = re.sub('\s+' , ' ', row.CtySt)&amp;nbsp; #this one works but is hard-coded
&amp;nbsp;&amp;nbsp;&amp;nbsp; newValue = re.sub('\s+' , ' ', row.getValue(fieldName)) #this one does not work but is soft-coded...&amp;nbsp; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You probably won't need affectedField variable any more&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:29:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-with-soft-coding-and-updating-row-values/m-p/488576#M38172</guid>
      <dc:creator>SolomonPulapkura</dc:creator>
      <dc:date>2021-12-11T21:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with soft coding and updating row values</title>
      <link>https://community.esri.com/t5/python-questions/trouble-with-soft-coding-and-updating-row-values/m-p/488577#M38173</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Great! This worked well. This embedded getValue() will also help while working with the rest of the code as this was just step one of many operations similar to this inorder to overhaul a badly organized/formatted table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you Solomon!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2012 18:00:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-with-soft-coding-and-updating-row-values/m-p/488577#M38173</guid>
      <dc:creator>JamesHensleigh</dc:creator>
      <dc:date>2012-07-06T18:00:45Z</dc:date>
    </item>
  </channel>
</rss>

