I have tried this. This is slightly beyond the scope of the question: You are getting input. First, it will be converted to a string (if it is a list, for example, from Beautiful soup); then to int, then swim.
He goes as far as possible. In the worst case, it returns everything uncured as a string.
def to_normal(soupCell): ''' converts a html cell from beautiful soup to text, then to int, then to float: as far as it gets. US thousands separators are taken into account. needs import locale''' locale.setlocale( locale.LC_ALL, 'english_USA' ) output = unicode(soupCell.findAll(text=True)[0].string) try: return locale.atoi(output) except ValueError: try: return locale.atof(output) except ValueError: return output
Anderas Aug 23 '17 at 12:46 on 2017-08-23 12:46
source share