user7776232
user7776232

Reputation: 86

Parsing U+00BE (¾) to number in python

I have a string which represents a ingredient with an amount, unit, description and so on.

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

I'd like to parse this string into an object which holds all the different characteristics of this ingredient.

The problem I'm facing 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 something like 3/4 or 0.75 back as result?

Upvotes: 3

Views: 192

Answers (1)

vZ10
vZ10

Reputation: 2676

import unicodedata
unicodedata.numeric(u'¾')

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

Upvotes: 6

Related Questions