Splitting lines in a file

William Park opengeometry at NOSPAM.yahoo.ca
Sun Jul 7 19:14:30 EDT 2002


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



More information about the Python-list mailing list