def generator():
nums = ['09', '98', '87', '76', '65', '54', '43']
s_chars = ['*', '&', '^', '%', '$', '#', '@',]
data = open("list.txt", "w")
for c in s_chars:
for n in nums:
data.write(c + n)
data.close()
I would like to add a newline after every "c + n".
Use the newline character "\n" to write a string to a file on a new line every time.
Use writelines() to write multiple lines to a file Add the newline character "\n" to the end of each string to write them on separate lines, otherwise the result will be in a single line.
In Python, the new line character “\n” is used to create a new line.
Change
data.write(c + n)
to
data.write("%s%s\n" % (c, n))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With