[Tutor] parse text file

Norman Khine norman at khine.net
Sat Jan 23 00:22:41 CET 2010


Hi

On Fri, Jan 22, 2010 at 7:44 PM, spir <denis.spir at free.fr> wrote:
> On Fri, 22 Jan 2010 14:11:42 +0100
> Norman Khine <norman at khine.net> wrote:
>
>> but my problem comes when i try to list the GLatLng:
>>
>> GLatLng(9.696333, 122.985992);
>>
>> >>> StartingWithGLatLng = soup.findAll(re.compile('GLatLng'))
>> >>> StartingWithGLatLng
>> []
>
> Don't about soup's findall. But the regex pattern string should rather be something like (untested):
>   r"""GLatLng\(\(d+\.\d*)\, (d+\.\d*)\) """
> capturing both integers.
>
> Denis
>
> PS: finally tested:
>
> import re
> s = "GLatLng(9.696333, 122.985992)"
> p = re.compile(r"""GLatLng\((\d+\.\d*)\, (\d+\.\d*)\)""")
> r = p.match(s)
> print r.group()         # --> GLatLng(9.696333, 122.985992)
> print r.groups()        # --> ('9.696333', '122.985992')
>
> s = "xGLatLng(1.1, 11.22)xxxGLatLng(111.111, 1111.2222)x"
> r = p.findall(s)
> print r                         # --> [('1.1', '11.22'), ('111.111', '1111.2222')]

Thanks for the help, but I can't seem to get the RegEx to work correctly.

Here is my input and output:

http://paste.lisp.org/+20BO/1

> ________________________________
>
> la vita e estrany
>
> http://spir.wikidot.com/
>



-- 
%>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or
chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] )


More information about the Tutor mailing list