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
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
def is_number(s): try: float(s) return True except ValueError: pass try: unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
def is_float(x): try: float(x) except ValueError: try: unicodedata.numeric(x) except (ValueError, TypeError): return False else: return True else: return True
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
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
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
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
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
def is_number(s): try: float(s) return True except: pass try: import unicodedata unicodedata.numeric(s) return True except: pass return False
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])
def is_number(field_val): try: float(field_val) return True except ValueError: pass try: import unicodedata as un un.numeric(field_val) return True except (TypeError, ValueError): pass return False
def count_pictures(k): try: float(k) return True except ValueError: pass try: import unicodedata unicodedata.numeric(k) return True except (TypeError, ValueError): pass return False
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
def is_number(s): try: float(s) return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
def is_number(s): try : float(s); return True; except ValueError: pass; try: import unicodedata; unicodedata.numeric(s); return True; except (TypeError, ValueError): pass; return False;
def is_number(string: str) -> bool: """See if a given string is a number (int or float)""" try: float(string) return True except ValueError: pass try: unicodedata.numeric(string) return True except (TypeError, ValueError): pass return False
def is_number(s): #for Verification of ID no. try: float(s) return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
def is_number(s): try: # 如果能运行float(s)语句,返回True(字符串s是浮点数) float(s) return True except ValueError: # ValueError为Python的一种标准异常,表示"传入无效的参数" pass # 如果引发了ValueError这种异常,不做任何事情(pass:不做任何事情,一般用做占位语句) try: import unicodedata # 处理ASCii码的包 for i in s: unicodedata.numeric(i) # 把一个表示数字的字符串转换为浮点数返回的函数 #return True return True except (TypeError, ValueError): pass return False
def is_digit(s): try: float(s) return True except ValueError: pass try: unicodedata.numeric(s) return True except (TypeError, ValueError): pass result = re.compile(r'^[-+]?[0-9]+,[0-9]+$').match(s) if result: return True return False
def __IsNumber(self, input_data): try: float(input_data) return True except ValueError: pass try: import unicodedata unicodedata.numeric(input_data) return True except (TypeError, ValueError): pass return False
def _is_pure_digital(element): try: float(element) return True except ValueError: pass try: import unicodedata unicodedata.numeric(element) return True except (TypeError, ValueError): pass return False
def is_number(s): try: float(s) return 0 except ValueError: pass try: import unicodedata unicodedata.numeric(s) return 0 except (TypeError, ValueError): pass return 1 print("Enter numbers only")
def number_judge(input_val): try: float(input_val) return True except ValueError: pass try: import unicodedata unicodedata.numeric(input_val) return True except (TypeError, ValueError): pass return False
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
def is_number(a): try: float(a) #先判断是否是浮动型 return True except ValueError as e: pass try: import unicodedata for i in a: #遍历字符串中的 unicodedata.numeric(i) #把一个表示数字的字符串转换为浮点数返回的函数 return True except ValueError as a: print(a) pass return False
def is_number(my_string): """Check if a string is a number or not""" try: float(my_string) return True except ValueError: pass try: import unicodedata unicodedata.numeric(my_string) return True except (TypeError, ValueError): pass return False
def is_number(s): """ Number validation check """ try: float(s) return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
def is_number(s): ''' Checks if string S is a number http://www.pythoncentral.io/how-to-check-if-a-string-is-a-number-in-python-including-unicode/ ''' try: float(s) return True except ValueError: pass try: unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
def is_number(s): # to judge whether the feature value is integer try: float(s) return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
def is_float(s): # test wheter a value is a float or not try: float(s) return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
def is_number(s): """Check if a varible is a number. Return True if it is. False if not""" try: float(s) return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
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
def is_number(s): try: float(s) return True except ValueError as e: # print(e) pass try: import unicodedata unicodedata.numeric(s) return True except (ValueError, TypeError): pass return False
def getQuantity(s): try: number = float(s) return s except ValueError: pass try: import unicodedata number = unicodedata.numeric(s) return ' ' + str(vulgarFractions.get(s, '')) except (TypeError, ValueError): pass try: number = float(Fraction(s)) return s except ValueError: pass if len(s) == 1: return '' tmp = '' for c in s: q = getQuantity(c) if not q: return '' else: tmp += q return tmp
def is_numeric(s): try: float(s) except ValueError: pass else: return True try: unicodedata.numeric(s) except (TypeError, ValueError): pass else: return True return False
def _convert_small_value(self, value, unit): power = unicodedata.numeric(unit) if unit else 1 value = value if value else '1' total = float(value) * power return total
def parse_ingredients(recipe_soup): ingredients = [] ingr_section = recipe_soup.find('section', attrs={'id':'ingredients'}) ingr_list = ingr_section.findAll('li', attrs={'itemprop':'ingredients'}) for item in ingr_list: quantity = item.find('span', {'class':'amount'}).text full_name = item.text.replace(quantity, '').strip() # The quantifier is always the first word of the full name quantifier = full_name.split(' ')[0] # If the full_name is only the quantifier set the name as # the quantifier if(full_name != quantifier): name = full_name.replace(quantifier, '') else: name = quantifier try: quantity = unicodedata.numeric(quantity) quantity = '{0:.2f}'.format(quantity) except: pass ingredients.append([quantity, quantifier, name]) return ingredients
def parse_number(text): """ This function accept a string that starts with a number e.g. 3.9兆円 It will read until a non-number is encountered, then stops e.g. 3.9兆円 will return 3900000000000.0 ditching the '円' """ text = text.replace(',', '') # remove comma from number like 16,460千株 text = text.replace(' ', '') # remove space from number like 16 460千株 leading_cursor = end_cursor = num = 0 total = [] while end_cursor < len( text): # get number at the front until it reach a non-number try: num = float(text[leading_cursor:end_cursor + 1]) except ValueError: # if the digit is not a number check if it is a multiplier e.g. 兆/千 if num != 0: # guard against residue 0 stored in total total.append(num) try: multiplier = unicodedata.numeric(text[end_cursor]) # to handle case like 1億千5百 where 千 without number in front stand for 1000 if num == 0 and all( i > multiplier for i in total ) and multiplier != 0: # guard against 零 being added total.append(multiplier) total = [multiply(x, num, multiplier) for x in total] leading_cursor = end_cursor + 1 except ValueError: # non value characters immediately end the calculation e.g. 円 break num = 0 end_cursor += 1 total.append(num) return sum(total)
def invoice_data_unicode_numbers(): """Creates a table of data (list of lists) for demo invoice selling unicode characters ;)""" lst_data = [[ "Item", "Quantity", "Part", "Description", "Unit price", "Price" ]] item = 0 total = 0 for i in range(4900, 8543): c = chr(i) # Find numbers other than digits if unicodedata.category(c) in [ "No", "Nl" ]: # "Nd" number digit, "Nl" number letter, "No" number other item += 1 quantity = i % 10 part = fr"\u{i:0>4X}" # hex code if you want to use this unicode character in str description = paragraph_description(c) unit_price = round(unicodedata.numeric(c), 2) price = quantity * unit_price row = [ item, quantity, part, description, f"${unit_price:10,.2f}", f"${price:10,.2f}" ] total += price lst_data.append(row) lst_data.append([ "", "", "", Paragraph("TOTAL", getSampleStyleSheet()["Normal"]), "", f"${total:10,.2f}" ]) return lst_data
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
def cast_to_number(s): ''' Cast a string to a float or integer. Tries casting to float first and if that works then it tries casting the string to an integer. (I thought I saw suggestion of that order somewhere when searching for what I used as `is_number()` check but cannot find source right now.) Returns a float, int, or if fails, False. (Where using, it shouldn't ever trigger returning `False` because checked all could be converted first.) based on fixed code from https://www.pythoncentral.io/how-to-check-if-a-string-is-a-number-in-python-including-unicode/ ''' try: number = float(s) try: number = int(s) return number except ValueError: pass return number except ValueError: pass try: import unicodedata num = unicodedata.numeric(s) return num except (TypeError, ValueError): pass return False
def is_number(s): """Check 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
def is_number(s): """Check if it is a number string. """ try: float(s) return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
def is_number(s): s = s.replace(',', '') # 10,000 -> 10000 s = s.replace(':', '') # 5:30 -> 530 s = s.replace('-', '') # 17-08 -> 1708 s = s.replace('/', '') # 17/08/1992 -> 17081992 try: float(s) return True except ValueError: pass try: unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
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
def isInteger(s): try: int(s) return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
def test_numeric_chars_contains_all_valid_unicode_numeric_and_digit_characters( ): set_numeric_hex = set(numeric_hex) set_numeric_chars = set(numeric_chars) set_digit_chars = set(digit_chars) set_decimal_chars = set(decimal_chars) for i in py23_range(0X110000): try: a = py23_unichr(i) except ValueError: break if a in set('0123456789'): continue if unicodedata.numeric(a, None) is not None: assert i in set_numeric_hex assert a in set_numeric_chars if unicodedata.digit(a, None) is not None: assert i in set_numeric_hex assert a in set_digit_chars if unicodedata.decimal(a, None) is not None: assert i in set_numeric_hex assert a in set_decimal_chars assert set_decimal_chars.isdisjoint(digits_no_decimals) assert set_digit_chars.issuperset(digits_no_decimals) assert set_decimal_chars.isdisjoint(numeric_no_decimals) assert set_numeric_chars.issuperset(numeric_no_decimals)
def is_number(a): try: float(a) return True except ValueError: pass try: import unicodedata unicodedata.numeric(a) return True except ValueError: pass return False
def is_number(string): """Also accepts '.' in the string. Function 'isnumeric()' doesn't""" try: float(string) return True except ValueError: pass try: import unicodedata unicodedata.numeric(string) return True except (TypeError, ValueError): pass return False
def is_number(potential_number): try: float(potential_number) if float(potential_number) > 0: return True else: return False except ValueError: pass try: import unicodedata unicodedata.numeric(potential_number) return True except (TypeError, ValueError): pass return False
def is_number(s): try: print(float(s))#float()构造函数 将指定参数解析并返回为float类型,如果参数不匹配转换错误会报错并中断 return True except ValueError as err: print('try1捕获到异常:',err) pass print('继续执行try2') try: import unicodedata print(unicodedata.numeric(s))#解析指定字符串返回其对应的float类型的数字 print('s.type=',type(unicodedata.numeric(s))) return True#使用unicodedata模块的numberic函数 except(TypeError ,ValueError ) as err: print('try2捕获到异常:',err) return False
def is_number(self, s): # this function comes from # http://www.pythoncentral.io/how-to-check-if-a-string-is-a-number-in-python-including-unicode/ try: float(s) return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
def GenerateNumeralEquivalenceTable(unicodecharlist): codepointMap = {} C = Collator() baseNumerals = [u'0', u'1', u'2', u'3', u'4', u'5', u'6', u'7', u'8', u'9'] baseKeys = {} for codepoint in baseNumerals: numval = unicodedata.numeric(codepoint) baseKeys[numval] = codepoint for codepoint in unicodecharlist: if unicodedata.category(codepoint) in ["No", "Nl"]: numval = unicodedata.numeric(codepoint) if numval in baseKeys: if codepoint != baseKeys[numval]: codepointMap[codepoint] = baseKeys[numval] return codepointMap
def is_number(string): ''' verificar si es un numero. ''' try: float(string) return True except ValueError: pass try: import unicodedata unicodedata.numeric(string) return True except (TypeError, ValueError): pass return False
def is_number(string: str) -> bool: """See if a given string is a number (int or float)""" try: float(string) return True except ValueError: pass try: import unicodedata unicodedata.numeric(string) return True except (TypeError, ValueError): pass return False
def is_number(s): try: float(s) print("f:", s, float(s), end = ' ') return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) print("u:", s, unicodedata.numeric(s), end = ' ') return True except (TypeError, ValueError): pass return False
def is_number(t): """ check to see if text is a number, from pythoncentral.org """ try: float(t) return True except ValueError: pass try: import unicodedata unicodedata.numeric(t) return True except (TypeError, ValueError): pass return False
def is_number(self,s): try: x = float(s) if x>0: return True else: return False except ValueError: pass try: unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False