newbie question

sharon k sharon.kim96 at gmail.com
Mon Aug 25 12:00:08 EDT 2008


much thanks, your instructions are clear, problem solved!

:)

On Mon, Aug 25, 2008 at 11:43 PM, Manuel Ebert <maebert at uos.de> wrote:

> Hi sharon,
>
> the problem is here that
> a = 12,123
> will actually create a tuple with two elements (namely 12 and 123):
> >> a = 12,123
> >> a
> (12, 123)
>
> Converting this to a string yields '(12, 123)', which is not what you want
> (sounds confusing, bit soon you'll see how many amazing things can be done
> like this :-)
>
> Try:
> >> a = "12,123"
> >> a = int(a.replace(',', ''))
>
> I don't know the urllib, but I suppose if you use it to fetch content from
> a web page it will return strings anyway.
>
>
> On Aug 25, 2008, at 5:14 PM, sharon k wrote:
>
>
>>
>> thank you for your prompt reply.
>>
>> sorry seems i run into another problem, as follow;
>>
>> >>> a = 12,123
>> >>> b = str(a)
>> >>> c = int(b.replace(',', ''))
>> Traceback (most recent call last):
>>  File "<stdin>", line 1, in <module>
>> ValueError: invalid literal for int() with base 10: '(12 123)'
>>
>> the comma has become an empty space, it cannot be converted to an integer.
>> i try the above in a winxp python command line.
>>
>>
>> On Mon, Aug 25, 2008 at 10:48 PM, Gerhard Häring <gh at ghaering.de> wrote:
>> sharon k wrote:
>> hi all,
>>
>> i am new to python.
>> >
>> i fetch a webpage with urllib, extract a few numbers in a format as
>> follow;
>>
>> 10,884
>> 24,068
>>
>> my question is how to remove the comma between the number, since i have to
>> add them up later.
>>
>> Strings have a replace method. Calling replace(",", "") on the string will
>> do the trick here.
>>
>> -- Gerhard
>>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080826/c33e2a17/attachment-0001.html>


More information about the Python-list mailing list