all Python 3localefunction
locale.atoi()
numbers and money
Converts a string to an integer under the current LC_NUMERIC rules, removing the local thousands separator.
Syntax
locale.atoi(string)
In essence it is int(delocalize(s)): the 'C' locale has no thousands separator, so the function acts like plain int() and rejects '1 000' and '1,000'. It does not round a fraction: atoi('1.5') raises ValueError. The result depends on setlocale() called anywhere in the process, so plain int() is enough for ordinary input.
Examples
import locale
print(locale.atoi('-7') + 1) # → -6
locale.atoi('1.5') # → ValueError: invalid literal for int() with base 10: '1.5'
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy