title: Wrap text in .txt file with Python3?
body: <p>Hello I explain my problem, I try to wrap my text in several lines, it's cool the methods work in the terminal, I have a wrap, but the problem is writing in my text file, impossible to wrap the text, I had to turn the function in all directions, I did not succeed, then I post the initial method if someone has an idea I am a taker</p>
  <pre><code>phrase = &quot;bla bla bla ceci est une phrase beaucoup trop longue pour ce que je doit réellement dire, en fait je peux même dire qu'elle ne sert a rien, mais du coup je doit quand même la tester&quot;
  
  # lim=40
  # line = []
  # with open(&quot;test.txt&quot;, &quot;w&quot;) as fiche:
  #     for s in phrase.split(&quot;\n&quot;):
  #         if s == &quot;&quot;:
  #             break
  #         word=0 
  #         for d in s.split():
  #             if word + len(d) + 1 &lt;= lim:
  #                 line.append(d)
  #                 word += len(d) + 1 
  #             else:
  #                 print(&quot; &quot;.join(line))
  #                 fiche.write(&quot; &quot;.join(line))
  
  #                 line = [d] 
  #                 word = len(d)
  #         if (len(line)):
  #             print(&quot; &quot;.join(line))
  #             fiche.write(&quot; &quot;.join(line))
  
  attempt n°2 :
  
  my_wrap = textwrap.TextWrapper(width = 40)
  wrap_list = my_wrap.wrap(text=phrase)
  
  with open(&quot;test.txt&quot;, &quot;w&quot;) as fiche:
      for line in wrap_list:
          print(line)
          fiche.write(&quot; &quot;.join(line))
  </code></pre>