title: Replacing part of a string and adding to it not producing the intended results
body: <p>I'm working on my first script: trying to grab all filenames from a folder (titled as <code>Thing_XXfilename.png</code>), removing some initial characters (<code>Thing_XX</code>) aswell as their extention and then inserting them one by one into a repeating line of code.</p>
  
  <p>I've tried dozens of variations but, for some reason that eludes me, the output is iterating through the characters of each original filename (no effect from the replace) and inserting them one after another into the code.</p>
  
  <pre><code>nf0 = 'Events.OnGameStart.Add( function ()\n\tif MyScript then\n'
  nf1 = ' if MyScript.Thing.XX'
  nf2 = ' then\n\t\telse\n\t\t\tMyScript.Thing.XX'
  nf3 = ' = {"Misc.", nil, nil, "'
  nf4 = '", "MyMod.XX'
  nf5 = '", "Thing_XX'
  nf6 = '", nil, nil, nil};\n\t\t\tend\n'
  nfn = ' end\nend)'
  
  import os
  
  f = open("textures.lua", "w")
  f.write(nf0)
  for files in os.listdir(r'C:\Users\Myuser\Textures'):
      for filename in files:
          line = filename.replace('Thing_XX', '')
          line = filename.replace('.png', '')
          f.write(nf1 + filename + nf2 + filename + nf3 + filename + nf4 + filename + nf5 + filename + nf6)
  f.write(nfn)
  f.close()
  </code></pre>
  
  <p>This should be producing:</p>
  
  <pre><code>if MyScript.Thing.XXfilename1 then
          else
              MyScript.Thing.XXfilename1 = {"Misc.", nil, nil, "filename1", "MyMod.XXfilename1", "Thing_XXfilename1", nil, nil, nil};
              end
  </code></pre>
  
  <p>But results in this instead:</p>
  
  <pre><code>if MyScript.Thing.XXT then
          else
              MyScript.Thing.XXT = {"Misc.", nil, nil, "T", "MyMod.XXT", "Thing_XXT", nil, nil, nil};
              end
  </code></pre>
  
  <p>The letter 'T' that shows up here, being the first letter of the first filename (and then repeated ad nauseam for each letter of all filenames).</p>