Help me split a string into elements
DFS
nospam at dfs.com
Sat Sep 4 17:55:52 EDT 2021
Typical cases:
lines = [('one\ntwo\nthree\n')]
print(str(lines[0]).splitlines())
['one', 'two', 'three']
lines = [('one two three\n')]
print(str(lines[0]).split())
['one', 'two', 'three']
That's the result I'm wanting, but I get data in a slightly different
format:
lines = [('one\ntwo\nthree\n',)]
Note the comma after the string data, but inside the paren.
splitlines() doesn't work on it:
print(str(lines[0]).splitlines())
["('one\\ntwo\\nthree\\n',)"]
I've banged my head enough - can someone spot an easy fix?
Thanks
More information about the Python-list
mailing list