writelines
expects an iterable of stringswrite
expects a single string.
line1 + "\n" + line2
merges those strings together into a single string before passing it to write
.
Note that if you have many lines, you may want to use "\n".join(list_of_lines)
.
Related Posts:
- What is the difference between rw+ and r+
- Print string to text file
- How can I concatenate str and int objects?
- Does Python have a string ‘contains’ substring method?
- How to convert list to string [duplicate]
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- Best way to convert string to bytes in Python 3?
- Pythonic way to create a long multi-line string
- Does Python have a string ‘contains’ substring method?
- TypeError: not all arguments converted during string formatting python
- raw_input function in Python
- ‘str’ object does not support item assignment
- How do I append one string to another in Python?
- How do I append one string to another in Python?
- Random string generation with upper case letters and digits
- How can I split and parse a string in Python?
- ValueError : I/O operation on closed file
- How to read a text file into a string variable and strip newlines?
- Python convert tuple to string
- Split a string into 2 in Python
- Best way to strip punctuation from a string
- No module named MySQLdb
- No module named MySQLdb
- How to check if the string is empty?
- How to find all occurrences of a substring?
- How do you use subprocess.check_output() in Python?
- How do I convert a list of ascii values to a string in python?
- Python TypeError: not enough arguments for format string
- How to add a string in a certain position?
- This can be done without regex:
- What does the ‘b’ character do in front of a string literal?
- Best way to replace multiple characters in a string?
- Writing a list to a file with Python
- Convert columns to string in Pandas
- How to delete a character from a string using Python
- Python: Get the first character of the first string in a list?
- How to convert string to binary?
- Remove the first character of a string
- Quoting backslashes in Python string literals
- Python string class like StringBuilder in C#?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- Remove all special characters, punctuation and spaces from string
- How to check if a string is a substring of items in a list of strings?
- Best way to replace multiple characters in a string?
- How can I splice a string?
- Detect whether a Python string is a number or a letter
- Finding all possible permutations of a given string in python
- How do I append one string to another in Python?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- ValueError: cannot index with vector containing NA / NaN values
- How to convert string to binary?
- Converting from a string to boolean in Python?
- How to check if type of a variable is string?
- Python – ‘ascii’ codec can’t decode byte
- How do I check if there are duplicates in a flat list?
- How to return dictionary keys as a list in Python?
- How can I print variable and string on same line in Python?
- UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xa0′ in position 20: ordinal not in range(128)
- How to open a file for both reading and writing?
- Remove quotes from String in Python
- Convert hex string to int in Python
- How can I check if character in a string is a letter? (Python)
- How can I check if character in a string is a letter? (Python)
- How can I find the first occurrence of a sub-string in a python string?
- How to concatenate items in a list to a single string?
- AttributeError: ‘list’ object has no attribute ‘lower’ gensim
- Find the nth occurrence of substring in a string
- How to convert ‘binary string’ to normal string in Python3?
- Properly formatted multiplication table
- How to get a function name as a string?
- Pandas error “Can only use .str accessor with string values”
- Python: Converting string into decimal number
- How to compare individual characters in two strings in Python 3
- Convert a Unicode string to a string in Python (containing extra symbols)python string unicode type-conversion
- How to repeat a string with spaces?
- AttributeError: ‘str’ object has no attribute ‘items’
- How to pad zeroes to a string?
- How do I convert a string to a double in Python?
- How can I copy a Python string?
- How to strip a specific word from a string?
- Split string using a newline delimiter with Python
- Checking if a string can be converted to float in Python
- Remove specific characters from a string in Python
- How to get ° character in a string in python?
- What is an easy way to implement fprintf in python?
- Python cant convert ‘list’ object to str error [closed]
- Determine if 2 lists have the same elements, regardless of order? [duplicate]
- How to append new data onto a new line
- Mutable strings in Python
- Python IOError: File not open for reading
- How can I check if a string contains ANY letters from the alphabet?
- Cannot concatenate ‘str’ and ‘float’ objects?
- How to repeat individual characters in strings in Python
- How to read a CSV file from a URL with Python?
- Find index of last occurrence of a substring in a string
- When to use %r instead of %s in Python? [duplicate]
- Python convert tuple to string
- Python – difference between two strings
- How to import a csv-file into a data array?
- TypeError: coercing to Unicode: need string or buffer