Python Snippets

Python Configuration

How to locate the site-packages directory

python -c 'import sys, pprint; pprint.pprint(sys.path)'


Convert string to number

String that represents a number which has commas to separate thousands. How can I convert this to a number in python?
Example int("1,000,000")

Functions used:

import locale
locale.setlocale( locale.LC_ALL, 'en_US.UTF-8' ) 
# 1000000
# 1000000.53
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.