title: "AttributeError: 'generator' object has no attribute 'replace' "
body: <p>I'm not sure why I'm seeing this error message: <code>AttributeError: 'generator' object has no attribute 'replace'</code> (on line: <code>modified_file = hex_read_file.replace(batch_to_amend_final, batch_amendment_final</code>).</p>
  <pre><code>import binascii, os, re, time
  
  os.chdir(...)
  files_to_amend = os.listdir(...)
  joiner = &quot;00&quot;
  
  # Allow user to input the text to be replaced, and with what
  while True:
      batch_to_amend3 = input(&quot;\n\nWhat number would you like to amend? \n\n &gt;&gt;&gt; &quot;)
      batch_amendment3 = input(&quot;\n\nWhat is the new number? \n\n &gt;&gt;&gt; &quot;)
      batch_to_amend2 = batch_to_amend3.encode()
      batch_to_amend = joiner.encode().join(binascii.hexlify(bytes((i,))) for i in batch_to_amend2)
      batch_amendment2 = batch_amendment3.encode()
      batch_amendment = joiner.encode().join(binascii.hexlify(bytes((i,))) for i in batch_amendment2)
  
  # Function to translate label files
  def lbl_translate(files_to_amend):
      with open(files_to_amend, 'rb') as read_file:
          read_file2 = read_file.read()
          hex_read_file = (binascii.hexlify(bytes((i,))) for i in read_file2)
          print(hex_read_file)
          modified_file = hex_read_file.replace(batch_to_amend, batch_amendment)
          with open(files_to_amend, 'wb') as write_file:
              write_file.write(modified_file)
              write_file.close()
              print(&quot;Amended: &quot; + files_to_amend)
  
  # Calling function to modify labels        
  for label in files_to_amend:
      lbl_translate(label)
  </code></pre>