How to read an entire column in python?

23 views
Skip to first unread message

lazyboy

unread,
Dec 13, 2005, 7:41:25 PM12/13/05
to python
Hi,

I'm a beginner of python prog language and have a file which has an
output similar to the below:

|---------------------------------------------|--------------------|
|ID |Name |
|---------------------------------------------|--------------------|
|129147032122-1103152530110-00216-1024424668 |suckboss.West|
|129147032122-1105123486137-28635-1355202588 |whatever.Central|
|129147032122-1103152583056-00412-0852863243 |peterpan.East|
|-------------------------------------------------------------------|

Is there a way to read an entire column in the file (i.e, name column)?

Thx,
-Chris

zavandi

unread,
Dec 14, 2005, 5:39:23 AM12/14/05
to pyt...@googlegroups.com

Not that I know of, but you can split the text on lines and then on
columns. Something like (session on ipython):

In [2]: print a


|---------------------------------------------|--------------------|
|ID |Name |
|---------------------------------------------|--------------------|
|129147032122-1103152530110-00216-1024424668 |suckboss.West|
|129147032122-1105123486137-28635-1355202588 |whatever.Central|
|129147032122-1103152583056-00412-0852863243 |peterpan.East|
|-------------------------------------------------------------------|

In [3]: [i.split('|')[2] for i in a.split('\n')]
Out[3]:
['--------------------',
'Name ',
'--------------------',
'suckboss.West',
'whatever.Central',
'peterpan.East',
'']

Reply all
Reply to author
Forward
0 new messages