reading fields from files in python without \t \n
PyGurus,
When I do readlines onto a file, with several columns, it returns it with data\t\n. I would like to have the first column in a array, second one in another and so on. First is that I would like to strip these characters \t\n, Second allocating the column to an array. finp=open("test1.dat","r") lines=finp.readlines() I would appreciate some pointers. Thanks DTC. |
read doc on module string
import string >>> x=open('/etc/passwd','r') >>> s=x.readlines() >>> s ['root:x:0:0:root:/root:/bin/bash\n', 'daemon:x:1:1:daemon:/usr/sbin:/bin/sh\n', 'bin:x:2:2:bin:/bin:/bin/sh\n', >>> string.strip(s[0]) 'root:x:0:0:root:/root:/bin/bash' >>> |
All times are GMT -5. The time now is 03:40 PM. |