Parsing U + 00BE (¾) for a number in python

I have a string that represents an ingredient with quantity, unit, description, etc.

¾ cup fresh pineapple, cut in small chunks or canned pineapple tidbits, drained

I would like to parse this string into an object that contains all the different characteristics of this ingredient.

The problem I'm running into is that I don't know how to convert the number (¾) from the Unicode representation to a normal number.

How can I parse this sentence to get a result like 3/4 or 0.75?

+3


source to share


1 answer


import unicodedata
unicodedata.numeric(u'¾')

      



will give you 0.75 (or without u if Python 3+)

+6


source







All Articles