tnoel999888 tnoel999888 -3 years ago 137
Python Question

Python Split String On Newline And Keep Newline

Is there a way to split a string containing a newline character into a list of strings where the newline character has been retained, eg.


would produce

["amount\n", "exceeds"]

Answer Source

Use splitlines(), passing True:


gives you:

["amount\n", "exceeds"]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download