In Python, what is the simplest way to convert a number enclosed in parentheses (string) to a negative integer (or float)?
For example, \'(4,301)\' to -4301, as commonly
Presumably you want to handle positive numbers as well as negative, which is missing from many of the answers thus far. I'm going to add a bit to the answer from mogul.
import locale
locale.setlocale( locale.LC_ALL, '')
my_str = '( 4,301 )'
positive = my_str.translate(None, '()')
result = locale.atoi(positive) if positive == my_str else -locale.atoi(positive)