When I use f.writelines('aaa')
in both Python2 and Python3, the string aaa
is written to the file, but what I expect is three separate lines of a
.
Here is the document of writelines
:
writelines(sequence_of_strings) -> None. Write the strings to the file.
Note that newlines are not added. The sequence can be any iterable object
producing strings. This is equivalent to calling write() for each string.
Please note that it accepts any iterable and str
is iterable, so why instead of writing a line for each item in the string, writelines()
simply writes a single string?
Should I need to use f.writelines(list('aaa'))
to get the desired result?
I wonder whether this is a deliberately consideration or simply a novel bug.