title: ArcGIS:Python - Adding Commas to a String
body: <p>In ArcGIS I have intersected a large number of zonal polygons with another set and recorded the original zone IDs and the data they are connected with. However the strings that are created are one long list of numbers ranging from 11 to 77 (each ID is 11 characters long). I am looking to add a &quot;,&quot; between each one making, it easier to read and export later as a .csv file. To do this I wrote this code:</p>
  <pre><code>def StringSplit(StrO,X):
    StrN = StrO #Recording original string 
    StrLen = len(StrN) 
    BStr = StrLen/X #How many segments are inside of one string
    StrC = BStr - 1 #How many times it should loop
    if StrC &gt; 0:  
      while StrC &gt; 1:
        StrN = StrN[ :((X * StrC) + 1)] + &quot;,&quot; + StrN[(X * StrC): ]
        StrC = StrC - 1
      while StrC == 1:
        StrN = StrN[:X+1] + &quot;,&quot; + StrN[(X*StrC):]
        StrC = 0 
      while StrC == 0:
        return StrN
    else:
      return StrN
  </code></pre>
  <p>The main issue is how it has to step through multiple rows (76) with various lengths (11 -&gt; 77). I got the last parts to work, just not the internal loop as it returns an error or incorrect outputs for strings longer than 22 characters.</p>
  <p><strong>Thus right now:</strong></p>
  <blockquote>
  <p><strong>1.</strong> 01234567890 returns 01234567890</p>
  <p><strong>2.</strong> 0123456789001234567890 returns 01234567890,01234567890</p>
  <p><strong>3.</strong> 012345678900123456789001234567890 returns either: Error or ,, or even ,,01234567890</p>
  </blockquote>
  <p>I know it is probably something pretty simple I am missing, but I can't seem remember what it is...</p>