Splitting lines in a file
Simon Foster
nospam at dsl.pipex.com
Mon Jul 8 19:00:30 EDT 2002
On 7 Jul 2002 23:14:30 GMT, William Park
<opengeometry at NOSPAM.yahoo.ca> wrote:
>Simon Foster <simon at uggs.demon.co.uk> wrote:
>> On 7 Jul 2002 22:30:55 GMT, William Park
>> <opengeometry at NOSPAM.yahoo.ca> wrote:
>>
>>>'1\n2\n3\n'.split() works as follows:
>>> 1\n2\n3\n -> 1\n2\n3 -> 1 \n 2 \n 3 -> 1 2 3
>>>
>>>'1\n2\n3\n'.split('\n') works as follows:
>>> 1\n2\n3\n -> 1 \n 2 \n 3 \n -> 1 2 3 ''
>>>where the last '\n' separates '3' and '' (null).
>>
>> Still seems odd!
>
>Not if you try to go backwards:
>
> 1 2 3 -> 1 \n 2 \n 3 -> 1\n2\n3
>
> 1 2 3 '' -> 1 \n 2 \n 3 \n '' -> 1\n2\n3\n
>
>--
>William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
>8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin
Don't understand what you mean here. You started from the same thing
and ended up in two different places. Am I missing something?
Surely whether I split on newline or arbitrary whitespace should not
matter if the arbitrary whitespace consists _only_ of newlines?
More information about the Python-list
mailing list