Re: Extracting text from a string

2006-09-07 Thread Paul Rubin
"Tim Williams" <[EMAIL PROTECTED]> writes: > or even more terse, > >>> print '\n'.join([i for i in s.splitlines ()[1::2]]) I think it's more robust to use a regexp. prices = re.findall('\$\d+\.\d\d', s) print '\n'.join(prices) -- http://mail.python.org/mailman/listinfo/python-list

Re: Extracting text from a string

2006-09-07 Thread Tim Williams
On 08/09/06, Tim Williams <[EMAIL PROTECTED]> wrote: > >>> print '\n'.join([i for i in s.splitlines() if i[0] == '$']) > $14.99 > $27.99 > $66.99 > $129.99 > $254.99 > or even more terse, >>> print '\n'.join([i for i in s.splitlines ()[1::2]]) $14.99 $27.99 $66.99 $129.99 $254.99 -- http://mail

Re: Extracting text from a string

2006-09-07 Thread Tim Williams
On 07/09/06, Anthra Norell <[EMAIL PROTECTED]> wrote: > s = ''' > $14.99 > , > $27.99 > , > $66.99 > , > $129.99 > , > $254.99 >''' > > >>> for line in [l.strip () for l in s.splitlines ()]: > if line [0] == '$': print line > > $14.99 > $27

Re: Extracting text from a string

2006-09-07 Thread Claudio Grondi
Tempo wrote: > This is the output I get: > > > > prices > > [ > $14.99 > , > $27.99 > , > $66.99 >

Re: Extracting text from a string + note

2006-09-07 Thread samir
Saluton! Tempo wrote: > I am having a little trouble extracting text from a string. The > string that I am dealing with is pasted below, and I want to > extract the prices that are contained in the string below. This string is absolutely an XML chunk. Just use xmllib. Adiaux Samir -- htt

Re: Extracting text from a string + note

2006-09-07 Thread bearophileHUGS
Tempo: > I am having a little trouble extracting text from a string. The > string that I am dealing with is pasted below, and I want to > extract the prices that are contained in the string below. This may help: >>> import re >>> reg = r"(?<= \$ ) (?: \d* \.? \d* )" >>> prices = re.compile(r

Re: Extracting text from a string

2006-09-07 Thread Tempo
This is the output I get: >>> prices [ $14.99 , $27.99 , $66.99 ,

Re: Extracting text from a string

2006-09-07 Thread Claudio Grondi
Tempo wrote: > Okay, so it sounds like I am in the right direction. However, I am not > sure that the text is in a string or some other format becasue the > string is enclosed in "[" and "]", not in ' '. > In case you have it like ['the string'], the actual string will be: ['the string'][0]. Just

Re: Extracting text from a string

2006-09-07 Thread Tempo
Okay, so it sounds like I am in the right direction. However, I am not sure that the text is in a string or some other format becasue the string is enclosed in "[" and "]", not in ' '. -- http://mail.python.org/mailman/listinfo/python-list

Re: Extracting text from a string

2006-09-07 Thread Claudio Grondi
Tempo wrote: > Hello. I am having a little trouble extracting text from a string. The > string that I am dealing with is pasted below, and I want to extract > the prices that are contained in the string below. Thanks in advanced > for any and all help. Thank you. > > > > >