how to find a lable quickly?

Josh Bloom joshbloom at gmail.com
Fri May 4 15:41:21 EDT 2007


I haven't used it myself, but I'm pretty sure you're going to get a lot of
pointers to
http://pyparsing.wikispaces.com/

Also you may want to start naming your variables something more descriptive.
IE
testResultsFile = open('test.txt','r')
testLines=testResultsFile.readlines()

for line in testLines:
   label = line.split( )
etc..

Another option is to use a Regular Expression which may speed this up for
you.
http://docs.python.org/lib/module-re.html

-Josh

On 5/4/07, wang frank <fw3 at hotmail.co.jp> wrote:
>
> Hi,
>
> I am a new user on Python and I really love it.
>
> I have a big text file with each line like:
>
> label             3
> teststart       5
> endtest      100
> newrun     2345
>
> I opened the file by uu=open('test.txt','r') and then read the data as
> xx=uu.readlines()
>
> In xx, it contains the list of each line. I want to find a spcefic labels
> and read the data. Currently, I
> do this by
> for ss in xx:
>    zz=ss.split( )
>   if zz[0] = endtest:
>     index=zz[1]
>
> Since the file is big and I need find more lables, this code runs slowly.
> Are there anyway to speed up the process? I thought to convert the data xx
> from list to a dictionay, so I can get the index quickly based on the
> label. Can I do that effeciently?
>
> Thanks
>
> Frank
>
> _________________________________________________________________
> メッセンジャーお友達紹介プレゼント第2弾開始!ラスベガス旅行プレゼント
> http://campaign.live.jp/dizon/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070504/6dcea2ca/attachment.html>


More information about the Python-list mailing list