Python: Ending line every N characters when writing to text file
Question: I am reading the webpage at "<https://google.com>" and writing as a string to
a notepad file. In the notepad file, I want to break and make a newline every
N characters while writing, so that I don't have to scroll horizontally in
notepad. I have looked up a number of solutions but none of them do this so
far. Thanks for any suggestions.

    
    
    import urllib.request
    
    page = urllib.request.urlopen("http://www.google.com")
    webfile = page.readlines()
    
    with open("file01.txt", 'w') as f:
       for line in webfile:
           f.write(str(line))
    
    f.close()
    


Answer: Better yet, use the
[textwrap](https://docs.python.org/2.7/library/textwrap.html) library. Then
you can use

    
    
    textwrap.fill(str(line))
    

and get breaks on whitespace and other useful additions.

