本文整理汇总了Python中unicodedata.numeric函数的典型用法代码示例。如果您正苦于以下问题:Python numeric函数的具体用法?Python numeric怎么用?Python numeric使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了numeric函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: isNumber
def isNumber(self, s):
"""
:type s: str
:rtype: bool
"""
# s = str(s.strip())
# if float(s):
# return True
# else:
# return s.isdigit()
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False
示例2: convert_proj_total
def convert_proj_total(total):
if len(total)==2:
if unicodedata.numeric(total[1])==0.5:
total=float(total[0])+unicodedata.numeric(total[1])
else:
total=float(total)
elif len(total)==3:
total=float(total[0:2])+unicodedata.numeric(total[2])
elif len(total)==1:
total=float(total)
return total
示例3: is_number
def is_number(s):
try:
s = float(s)
if math.isnan(s):
return False
return True
except ValueError:
try:
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
return False
示例4: is_number
def is_number(s):
try:
float(s)
return True
except ValueError:
pass
try:
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False
示例5: is_number
def is_number(s):
try:
float(s)
return True
except (ValueError, TypeError):
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
示例6: is_number
def is_number(self, s):
try:
float(s)
return True
except ValueError:
return False
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
return False
示例7: is_number
def is_number(self, s):
'''returns true if string is a number'''
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False
示例8: is_number
def is_number(s):
try:
float(s)
return True
except:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except:
pass
return False
示例9: isDigit
def isDigit(self,s):
s=s.replace(",","")
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False
示例10: test_parse_rand_utf8
def test_parse_rand_utf8(self):
h2o.beta_features = True
SYNDATASETS_DIR = h2o.make_syn_dir()
tryList = [
(1000, 1, 'cA', 120),
(1000, 1, 'cG', 120),
(1000, 1, 'cH', 120),
]
print "What about messages to log (INFO) about unmatched quotes (before eol)"
# got this ..trying to avoid for now
# Exception: rjson error in parse: Argument 'source_key' error: Parser setup appears to be broken, got AUTO
for (rowCount, colCount, hex_key, timeoutSecs) in tryList:
SEEDPERFILE = random.randint(0, sys.maxint)
csvFilename = 'syn_' + str(SEEDPERFILE) + "_" + str(rowCount) + 'x' + str(colCount) + '.csv'
csvPathname = SYNDATASETS_DIR + '/' + csvFilename
print "\nCreating random", csvPathname
write_syn_dataset(csvPathname, rowCount, colCount, SEEDPERFILE)
parseResult = h2i.import_parse(path=csvPathname, schema='put', header=0,
hex_key=hex_key, timeoutSecs=timeoutSecs, doSummary=False)
print "Parse result['destination_key']:", parseResult['destination_key']
inspect = h2o_cmd.runInspect(None, parseResult['destination_key'], timeoutSecs=60)
print "inspect:", h2o.dump_json(inspect)
numRows = inspect['numRows']
self.assertEqual(numRows, rowCount, msg='Wrong numRows: %s %s' % (numRows, rowCount))
numCols = inspect['numCols']
self.assertEqual(numCols, colCount, msg='Wrong numCols: %s %s' % (numCols, colCount))
for k in range(colCount):
naCnt = inspect['cols'][k]['naCnt']
self.assertEqual(0, naCnt, msg='col %s naCnt %d should be 0' % (k, naCnt))
stype = inspect['cols'][k]['type']
self.assertEqual("Enum", stype, msg='col %s type %s should be Enum' % (k, stype))
#**************************
# for background knowledge; (print info)
import unicodedata
u = unichr(233) + unichr(0x0bf2) + unichr(3972) + unichr(6000) + unichr(13231)
for i, c in enumerate(u):
print i, '%04x' % ord(c), unicodedata.category(c),
print unicodedata.name(c)
# Get numeric value of second character
print unicodedata.numeric(u[1])
示例11: is_number
def is_number(a):
try:
float(a)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(a)
return True
except (TypeError, ValueError):
pass
return False
示例12: is_integer
def is_integer(s):
try:
int(s)
return True
except ValueError:
pass
try:
from unicodedata import numeric
numeric(s)
return True
except (TypeError, ValueError):
pass
return False
示例13: is_number
def is_number(string):
s = string.replace(',','')
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False
示例14: getdetails
def getdetails(self, text):
chardetails = {}
for character in text:
chardetails[character] = {}
chardetails[character]['Name'] = unicodedata.name(character)
chardetails[character]['HTML Entity'] = str(ord(character))
chardetails[character]['Code point'] = repr(character)
try:
chardetails[character]['Numeric Value'] = \
unicodedata.numeric(character)
except:
pass
try:
chardetails[character]['Decimal Value'] = \
unicodedata.decimal(character)
except:
pass
try:
chardetails[character]['Digit'] = unicodedata.digit(mychar)
except:
pass
chardetails[character]['Alphabet'] = str(character.isalpha())
chardetails[character]['Digit'] = str(character.isdigit())
chardetails[character]['AlphaNumeric'] = str(character.isalnum())
chardetails[character]['Canonical Decomposition'] = \
unicodedata.decomposition(character)
chardetails['Characters'] = list(text)
return chardetails
示例15: fromRoman
def fromRoman(S):
"Convert a roman numeral string to binary"
if type(S) is Roman: return int(S) #in case it already IS Roman
result=0
# Start by converting to upper case for convenience
us = S.strip().upper()
try:
s = unicode(us)
except UnicodeEncodeError: # IronPython bug
s = us
#test for zero
if s == '' or s == u'N' or s[:5] == u'NULLA': # Latin for "nothing"
return 0
# This simplified algorithm (V.Cole) will correctly convert any correctly formed
# Roman number. It will also convert lots of incorrectly formed numbers, and will
# accept any combination of ASCII 'MCDLXVI' and unicode Roman Numeral code points.
held = 0 # this is the memory for the previous Roman digit value
for c in s: #this will get the value of a sequence of unicode Roman Numeral points
try: # may be a normal alphabetic character
val = _Rom[c] #pick the value out of the dict
except KeyError: # may be a unicode character with a value
try:
val = int(unicodedata.numeric(c)) # retrieve the value from the unicode chart
except:
raise InvalidRomanNumeralError, 'incorrectly formatted Roman Numeral '+repr(S)
if val > held: # if there was a smaller value to the left, subtract it
result -= held
else: # otherwise add it
result += held
held = val # try this loop's letter value on the next loop
result += held #the last letter value is always added
return result