About 1,760,000 results
Open links in new tab
    Upvotes11Top Answeredited Jun 15, 2017 at 12:25

    Have you tried to modify your string the following way:

    stringtowrite = "abcd ||\nefgh||\niklk"

    f = open(save_dir + os.path.sep +count+"_report.txt", "w")
    f.write(stringtowrite)
    f.close()

    OR:

    stringtowrite = """abcd ||
    efgh||
    iklk"""
    Content Under CC-BY-SA license
    Was this helpful?
  1. Writing a string (with new lines) in Python - Stack Overflow

  2. Add a newline character in Python - 6 Easy Ways! - AskPython

  3. Python New Line in String [4 Unique Ways] - Python …

    Apr 19, 2024 · Do you want to know how to add a new line to a string in Python? In this Python tutorial, we will show you multiple ways to add a new line in a string with multiple examples and scenarios.

  4. Handle line breaks (newlines) in strings in Python

    May 18, 2023 · To create a line break at a specific location in a string, insert a newline character, either \n or \r\n. s = 'Line1\nLine2\nLine3' print(s) # Line1 # Line2 # Line3 s = 'Line1\r\nLine2\r\nLine3' print(s) # Line1 # Line2 # Line3. …

  5. Python String - Append Newline

  6. Python New Line: How to add a new line - Flexiple

  7. Python New Line: Methods for Code Formatting - DataCamp

  8. How to Specify New Lines in a Python String - Squash

  9. Python Strings: Learn How to Add Line Breaks - Devsheet

  10. python - How do I specify new lines in a string in order to write ...