parsing tabs in a string

Andrew Thompson andrew.thompson at ashecastle.com
Mon Sep 23 13:22:29 EDT 2002


Andrew,
 
You might find it easier to split up the line first into a collection of
fields using the tab-delimiter, and then just access the collection
As an array :
 
'
import string
 
aString='abc \t def \t xyz  \t'
 
anArray = string.split ( aString , '\t')
 
anArray[0] now equals
 
'abc '
 
 
 
Andrew
 
-----Original Message-----
From: python-list-admin at python.org [mailto:python-list-admin at python.org]
On Behalf Of Andrew Alzner
Sent: 23 September 2002 18:11
To: python-list at python.org
Subject: parsing tabs in a string
 
Hello,
 
I'm getting to know Python and have a quick question for something I
don't understand.
 
I'm trying to parse information extracted from a spreadsheet which is
tab separated. Here is a simplified version of what I have:
 
list=['"103-01a-17"\t2\t33\t256\t227\n']
y=list[0]
print y.find("\t")
print y.find("\t",1)
 
I thought the second .find should return the second occurence of "\t".
To get the index of the second tab I have to type:
 
print y.find("\t",13)
 
This doesn't make sense to me. Can someone help me please.
 
Thanks,
Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20020923/b6861d29/attachment.html>


More information about the Python-list mailing list