[Tutor] How do I save the output of the rotor module?
dyoo at hkn.eecs.berkeley.edu
Fri Nov 7 13:04:29 EST 2003
> The code now decrypts successfully. Although it leaves the file in the
> form of one large string instead of a list of strings. The split()
> method returns it to a list of strings but *removes* the \n's. I could
> loop through the list and append newlines to each string. Can split() be
> instructed to perform the split without removing the newlines?
split() can't, but splitlines() can.
>>> s = "hello world\nthis is a test\n"
['hello', 'world', 'this', 'is', 'a', 'test']
['hello world', 'this is a test']
['hello world\n', 'this is a test\n']
splitlines() can take in an optional 'keepends' parameter: if we send it a
true value, then it'll keep the newlines.
We can find out more about the string methods in the Library Reference:
I hope this helps!
More information about the Tutor