Newbie Question: Regular Expressions

Terry Reedy tjreedy at home.com
Thu Jul 12 13:15:40 EDT 2001


<fett at tradersdata.com> wrote in message
news:mailman.994953021.32263.python-list at python.org...
> I have a really dumb program that i would like to make smarter.  I need
> to take a file on my hard drive and filter out everything except for the
> standings which are written in it.  I have tried to use regular
> expressions with no success, but i still think that they are probably
> the best way.  I created the following simple fix, but it is unreliable
> if the data changed posistions.

Try S.find('League Standings') , then find the first thing you *don't*
want.

>
>
> input = open('rawdata', 'r')
> S = input.read()
> print S[4021:6095]
>
> Output :
>    League Standings
>    American League
>      EAST W L PCT GB HOME ROAD EAST CENT WEST NL L10 STRK
>      Red Sox 43 29 .597 - 23-15 20-14 23-13 8-7 6-6 6-3 6-4 L2
>      Yankees 41 31 .569 2.0 21-15 20-16 19-11 12-9 5-7 5-4 6-3 W2
>      Blue Jays 35 38 .479 8.5 18-20 17-18 14-13 6-7 11-13 4-5 5-5 W3
>      Orioles 34 39 .466 9.5 20-20 14-19 15-17 9-12 6-5 4-5 5-5 L1
> ........( it continues with all the standings)
>
>
> Also could you tell me if its possible to download the data from the
> web-page in python so that it doesnt even have to deal with opening the
> file.

I believe you want standard library module urllib so you can say
'S=urlopen(url).read()' (never used myself yet, so check details).

Terry J. Reedy






More information about the Python-list mailing list