How do I use Python to convert a string to a number if it has commas in it as thousands separators?
<p>I have a string that represents a number which uses commas to separate thousands.  How can I convert this to a number in python?</p>

<pre><code>&gt;&gt;&gt; int("1,000,000")
</code></pre>

<p>Generates a <code>ValueError</code>.</p>

<p>I could replace the commas with empty strings before I try to convert it, but that feels wrong somehow.  Is there a better way?</p>
