title: How to remove <_io.TextIOWrapper name='xyz.txt' mode='w' encoding='UTF-8'> from file?
body: <p>I am creating a file when running a function for an output that I need to work on, but in addition to the desired output, I get &lt;_io.TextIOWrapper name='xyz.txt' mode='w' encoding='UTF-8'> as output as well in every line of the text file.</p>
  
  <p>Example code:</p>
  
  <pre><code>def stimcount():
  with open('results.txt', 'w') as f:
      for rel_node in root.findall("emospan:CharacterRelation",ns):
          if rel_node.attrib['Relation']=="Stimulus":
              source = rel_node.attrib['Governor']
              target = rel_node.attrib['Dependent']
              for span_node in root.findall("emospan:CharacterEmotion",ns):
                  if span_node.attrib[my_id]==source:
  
                      print(span_node.attrib['Emotion'])
  
                  if span_node.attrib[my_id]==target:
                      print(span_node.attrib)
                      print(span_node.attrib, f, file=f)
  </code></pre>
  
  <p>what should I add to prevent this from happening?
  I tried adding (..., encoding='utf-8') to the open command, but it had no effect.</p>
  
  <p>Thanks in advance!</p>