title: Writing to files in ASCII with Python3, not UTF8
body: <p>I have a program that I created with two sections. </p>
  
  <p>The first one copies a text file with an integer in the middle of the file name in this format. </p>
  
  <pre><code>file = "Filename" + "str(int)" + ".txt" 
  </code></pre>
  
  <p>the user can create as many copies of the file that they would like.</p>
  
  <p>The second part of the program is what I am having the problem with. There is an integer at the very bottom of the file that is to correspond with the integer in the file name. After the first part is done, I open each file one at a time in <code>"r+"</code> read/write format. So I can <code>file.seek(1000)</code> to about where the integer is in the file.</p>
  
  <p>Now in my opinion the next part should be easy. I should just simply have to write str(int) into the file right here. But it wasn't that easy. It worked just fine doing it like that in Linux at home, but at work on Windows it proved difficult. What I ended up having to do after <code>file.seek(1000)</code> is write to the file using Unicode UTF-8. I accomplished this with this code snippet of the rest of the program. I will document it so that it is able to be understood what is going on. Instead of having to write this in Unicode, I would love to be able to write this in good old regular English ASCII characters. Eventually this program will be expanded to include a lot more data at the bottom of each file. Having to write the data in Unicode is going to make things extremely difficult. If I just write the data without turning it into Unicode this is the result. This string is supposed to say <code>#2 =1534</code>, instead it says <code>#2 =ㄠ㌵433.</code></p>
  
  <p>If someone can show me what I am doing wrong that would be great. I would love to just use something like <code>file.write('1534')</code> to write the data to the file instead of having to do it in Unicode UTF-8. </p>
  
  <pre><code>while a1 &lt; d1 :
      file = "file" + str(a1) + ".par"
      f = open(file, "r+")
      f.seek(1011)
      data = f.read()  #reads the data from that point in the file into a variable.
      numList= list(str(a1)) # "a1" is the integer in the file name. I had to turn the integer into a list to accomplish the next task.
      replaceData = '\x00' + numList[0] + '\x00' + numList[1] + '\x00' + numList[2] + '\x00' + numList[3] + '\x00' #This line turns the integer into Utf 8 Unicode. I am by no means a Unicode expert.
      currentData = data #probably didn't need to be done now that I'm looking at this.
      data = data.replace(currentData, replaceData) #replaces the Utf 8 string in the "data" variable with the new Utf 8 string in "replaceData."
      f.seek(1011) # Return to where I need to be in the file to write the data.
      f.write(data) # Write the new Unicode data to the file
      f.close() #close the file
      f.close() #make sure the file is closed (sometimes it seems that this fails in Windows.)
      a1 += 1 #advances the integer, and then return to the top of the loop
  </code></pre>