编辑:更好的例证,可能的错误修正>>> def get_unit(ustr):
... if ustr == '': return 'u'
... return ustr.lower()
...
>>> import re
>>> r=re.compile('([1-9][0-9]*)([kKmMbBgG]?)')
>>> units={'k':1000,'m':1000000,'g':1000000000,'b':1000000000,'u':1}
>>> result=r.match('120k')
>>> int(result.group(1))*units[get_unit(result.group(2))]
120000
>>> result=r.match('44')
>>> int(result.group(1))*units[get_unit(result.group(2))]
44
>>> result=r.match('44M')
>>> int(result.group(1))*units[get_unit(result.group(2))]
44000000
>>>