本文整理汇总了Python中locale.atoi方法的典型用法代码示例。如果您正苦于以下问题:Python locale.atoi方法的具体用法?Python locale.atoi怎么用?Python locale.atoi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类locale
的用法示例。
在下文中一共展示了locale.atoi方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: numberFromString
# 需要导入模块: import locale [as 别名]
# 或者: from locale import atoi [as 别名]
def numberFromString(self, string):
# Uses the current system locale, irrespective of language choice.
# Returns None if the string is not parsable, otherwise an integer or float.
if platform=='darwin':
return self.float_formatter.numberFromString_(string)
else:
try:
return locale.atoi(string)
except:
try:
return locale.atof(string)
except:
return None
# Returns list of preferred language codes in RFC4646 format i.e. "lang[-script][-region]"
# Where lang is a lowercase 2 alpha ISO 639-1 or 3 alpha ISO 639-2 code,
# script is a capitalized 4 alpha ISO 15924 code and region is an uppercase 2 alpha ISO 3166 code
示例2: get_values
# 需要导入模块: import locale [as 别名]
# 或者: from locale import atoi [as 别名]
def get_values(soup, row_class):
"""get values from a specific summary row based on the row class"""
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') # for number parsing
values = []
cells = soup.find('tr', {'class': row_class}).find_all('td')
for elem in cells[1:]:
# if there's a child span with class "macro-value", use its value
# otherwise use the cell text
span = elem.find('span', {'class': 'macro-value'})
if span:
value = span.text
else:
value = elem.text
if value.strip() != '':
values.append(locale.atoi(value))
return values
示例3: is_number
# 需要导入模块: import locale [as 别名]
# 或者: from locale import atoi [as 别名]
def is_number(s):
try:
locale.atof(s)
return True
except ValueError:
pass
# put string like '3\/32' into numbers
try:
special_str = '\/'
pos = s.find(special_str)
if pos > 0:
locale.atoi(s[:pos])
locale.atoi(s[pos+len(special_str):])
return True
except ValueError:
pass
return False
示例4: get_method
# 需要导入模块: import locale [as 别名]
# 或者: from locale import atoi [as 别名]
def get_method(self):
def custom_int(data):
data = locale.atoi(data)
return int(data)
return custom_int
示例5: cast
# 需要导入模块: import locale [as 别名]
# 或者: from locale import atoi [as 别名]
def cast(self, value):
if self.regex.match(value):
return int(value)
try:
value = float(value)
except:
return locale.atoi(value)
if value.is_integer():
return int(value)
else:
raise ValueError('Invalid integer: %s' % value)
示例6: cast
# 需要导入模块: import locale [as 别名]
# 或者: from locale import atoi [as 别名]
def cast(self, value):
if value in ('', None):
return None
try:
value = float(value)
except:
return locale.atoi(value)
if value.is_integer():
return int(value)
else:
raise ValueError('Invalid integer: %s' % value)
示例7: _test_atoi
# 需要导入模块: import locale [as 别名]
# 或者: from locale import atoi [as 别名]
def _test_atoi(self, value, out):
self.assertEqual(locale.atoi(value), out)
示例8: convertNumber
# 需要导入模块: import locale [as 别名]
# 或者: from locale import atoi [as 别名]
def convertNumber(data):
locale.setlocale( locale.LC_ALL, 'en_US.UTF-8')
num = locale.atoi(data)
if is_number(num):
return num
else:
msg = '[*] %s is not a number' % (data)
logging.error(msg)
return 0
示例9: cast
# 需要导入模块: import locale [as 别名]
# 或者: from locale import atoi [as 别名]
def cast(self, value):
if value in ('', None):
return None
try:
value = float(value)
except:
return locale.atoi(value)
if value.is_integer():
return int(value)
else:
raise ValueError('Invalid integer: %s' % value)
示例10: CreateFromString
# 需要导入模块: import locale [as 别名]
# 或者: from locale import atoi [as 别名]
def CreateFromString(cls, text, consider_locale=True):
"""
Create a FractionValue from a string.
:param str text:
The text with a fraction-value, that is, three integers separated by space and slash
respectively.
<value> <value>/<value>
:param bool consider_locale:
Consider the locale on converting string to float
:rtype: FractionValue
:returns:
The fraction value
:raises ValueError:
If the text is not convertible to a FractionValue
"""
text = str(text).strip()
if consider_locale:
string_to_float_callable = FloatFromString
else:
string_to_float_callable = float
# First try to match only the fractional part.
m = cls._FRACTION_PARTIAL_RE.match(text)
if m is not None:
number = None
else:
# If can't match a fraction try a mixed number
m = cls._FRACTION_RE.match(text)
if m is None:
raise ValueError('Please enter a text in the form: "5 3/4"')
number = m.group("float")
if number is None:
number = 0.0
else:
number = string_to_float_callable(number)
if m.group("numerator") is not None and m.group("denominator") is not None:
numerator = string_to_float_callable(m.group("numerator"))
denominator = locale.atoi(m.group("denominator"))
fraction = Fraction(numerator, denominator)
else:
fraction = Fraction(0.0, 1.0)
return FractionValue(number, fraction)
示例11: unpickleVars
# 需要导入模块: import locale [as 别名]
# 或者: from locale import atoi [as 别名]
def unpickleVars(pdb2pqrID):
""" Converts instance pickle from PDB2PQR into a dictionary for APBS """
apbsOptions = {}
#pfile = open("/home/samir/public_html/pdb2pqr/tmp/%s-input.p" % pdb2pqrID, 'r')
pfile = open("%s%s%s/%s-input.p" % (INSTALLDIR, TMPDIR, pdb2pqrID, pdb2pqrID), 'r')
inputObj = pickle.load(pfile)
pfile.close()
myElec = inputObj.elecs[0]
apbsOptions['pqrname'] = pdb2pqrID+'.pqr'
apbsOptions['pdbID'] = inputObj.pqrname[:-4]
if myElec.cgcent[0:3] == "mol":
apbsOptions['coarseGridCenterMethod'] = "molecule"
apbsOptions['coarseGridCenterMoleculeID'] = locale.atoi(myElec.cgcent[4:])
else:
apbsOptions['coarseGridCenterMethod'] = "coordinate"
apbsOptions['coarseGridCenter'] = myElec.cgcent
if myElec.fgcent[0:3] == "mol":
apbsOptions['fineGridCenterMethod'] = "molecule"
apbsOptions['fineGridCenterMoleculeID'] = locale.atoi(myElec.fgcent[4:])
else:
apbsOptions['fineGridCenterMethod'] = "coordinate"
apbsOptions['fineGridCenter'] = myElec.fgcent
if myElec.gcent[0:3] == "mol":
apbsOptions['gridCenterMethod'] = "molecule"
apbsOptions['gridCenterMoleculeID'] = locale.atoi(myElec.gcent[4:])
else:
apbsOptions['gridCenterMethod'] = "coordinate"
apbsOptions['gridCenter'] = myElec.gcent
if myElec.lpbe == 1:
apbsOptions['solveType'] = 'linearized'
elif myElec.npbe == 1:
apbsOptions['solveType'] = 'nonlinearized'
if len(myElec.ion) == 0:
apbsOptions['mobileIonSpecies[0]'] = None
else:
apbsOptions['mobileIonSpecies[1]'] = myElec.ion
if len(myElec.write) <= 1:
apbsOptions['format'] = 'dx'
else:
apbsOptions['format'] = myElec.write[1]
apbsOptions['calculationType'] = myElec.method
apbsOptions['dime'] = myElec.dime
apbsOptions['pdime'] = myElec.pdime
apbsOptions['async'] = myElec.async