"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
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
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
Tempo wrote:
> This is the output I get:
>
>
>
>
prices
>
> [
> $14.99
> ,
> $27.99
> ,
> $66.99
>
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
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
This is the output I get:
>>> prices
[
$14.99
,
$27.99
,
$66.99
,
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
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
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.
>
>
>
>
>
10 matches
Mail list logo