I am using python to generate a test file used for programming. In this file, I have several auto-generated comments. Problem is, some of these comments can be quite long, and the software which reads the file generates an error if a line is too long.
What I am looking for is a method of breaking a string with '\n# '. The location of these line returns should limit the width of any one line to be less than a certain width. Below is an example of what I want to do. I need code that generates "broken_line" from "long_line".
long_line = "# alpha || bravo || charlie || delta || echo are the first 5 elements of NATO"
broken_line = "# alpha || bravo || charlie ||\n# delta || echo are the first \n# 5 elements of NATO"
>>>print long_line
# alpha || bravo || charlie || delta || echo are the first 5 elements of NATO
>>>print broken_line
# alpha || bravo || charlie ||
# delta || echo are the first
# 5 elements of NATO