<div dir="ltr">much thanks, your instructions are clear, problem solved!<br><br>:)<br><br><div class="gmail_quote">On Mon, Aug 25, 2008 at 11:43 PM, Manuel Ebert <span dir="ltr"><<a href="mailto:maebert@uos.de">maebert@uos.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi sharon,<br>
<br>
the problem is here that<br>
a = 12,123<br>
will actually create a tuple with two elements (namely 12 and 123):<br>
>> a = 12,123<br>
>> a<br>
(12, 123)<br>
<br>
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 :-)<br>
<br>
Try:<br>
>> a = "12,123"<br>
>> a = int(a.replace(',', ''))<br>
<br>
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.<div><div></div><div class="Wj3C7c"><br>
<br>
On Aug 25, 2008, at 5:14 PM, sharon k wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
thank you for your prompt reply.<br>
<br>
sorry seems i run into another problem, as follow;<br>
<br>
>>> a = 12,123<br>
>>> b = str(a)<br>
>>> c = int(b.replace(',', ''))<br>
Traceback (most recent call last):<br>
File "<stdin>", line 1, in <module><br>
ValueError: invalid literal for int() with base 10: '(12 123)'<br>
<br>
the comma has become an empty space, it cannot be converted to an integer. i try the above in a winxp python command line.<br>
<br>
<br>
On Mon, Aug 25, 2008 at 10:48 PM, Gerhard Häring <<a href="mailto:gh@ghaering.de" target="_blank">gh@ghaering.de</a>> wrote:<br>
sharon k wrote:<br>
hi all,<br>
<br>
i am new to python.<br>
><br>
i fetch a webpage with urllib, extract a few numbers in a format as follow;<br>
<br>
10,884<br>
24,068<br>
<br>
my question is how to remove the comma between the number, since i have to add them up later.<br>
<br>
Strings have a replace method. Calling replace(",", "") on the string will do the trick here.<br>
<br>
-- Gerhard<br>
<br>
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
<br>
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</blockquote>
<br>
</div></div></blockquote></div><br></div>