本文整理汇总了Python中string.atoi方法的典型用法代码示例。如果您正苦于以下问题:Python string.atoi方法的具体用法?Python string.atoi怎么用?Python string.atoi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string
的用法示例。
在下文中一共展示了string.atoi方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: import string [as 别名]
# 或者: from string import atoi [as 别名]
def parse (self, vstring):
match = self.version_re.match(vstring)
if not match:
raise ValueError, "invalid version number '%s'" % vstring
(major, minor, patch, prerelease, prerelease_num) = \
match.group(1, 2, 4, 5, 6)
if patch:
self.version = tuple(map(string.atoi, [major, minor, patch]))
else:
self.version = tuple(map(string.atoi, [major, minor]) + [0])
if prerelease:
self.prerelease = (prerelease[0], string.atoi(prerelease_num))
else:
self.prerelease = None
示例2: _parsestats
# 需要导入模块: import string [as 别名]
# 或者: from string import atoi [as 别名]
def _parsestats(self, rawstats):
plug_re = re.compile("^[0-9]")
lines = string.split(rawstats, "\n")
for line in lines:
line = string.strip(line)
if plug_re.match(line):
parts = string.split(line, "|")
number = string.atoi(string.strip(parts[0]))
name = string.strip(parts[1])
status = string.strip(parts[2])
bootdelay = string.atoi(string.strip(string.split(parts[3])[0]))
password = string.strip(parts[4])
if password == "(none)":
password = None
defaultstate = string.strip(parts[5])
self.plugs[number] = NPSPlug(number, name, status, bootdelay, password, defaultstate)
elif line[:10] == "Disconnect":
self.timeout = string.atoi(string.strip(string.split(line)[2]))*60
示例3: __init__
# 需要导入模块: import string [as 别名]
# 或者: from string import atoi [as 别名]
def __init__(self):
"""
初始化方法
"""
import string
import threading
if FilePersistence._init:
return
self._lock = threading.Lock()
self._inspect_results = {}
self._ob_paths = {} # 需要观察路径下节点变化的路径列表
self._touch_paths = {} # 针对临时节点,需要不断touch的路径列表
self._base = config.GuardianConfig.get(config.STATE_SERVICE_HOSTS_NAME)
self._mode = string.atoi(config.GuardianConfig.get("PERSIST_FILE_MODE", FilePersistence._file_mode), 8)
self._interval = string.atof(config.GuardianConfig.get("PERSIST_FILE_INTERVAL", "0.4"))
self._timeout = string.atof(config.GuardianConfig.get("PERSIST_FILE_TIMEOUT", "3"))
if not os.path.exists(self._base):
os.makedirs(self._base, self._mode)
self._session_thread = threading.Thread(target=self._thread_run)
FilePersistence._init = True
self._session_thread.daemon = True
self._session_thread.start()
示例4: collect_memory_info
# 需要导入模块: import string [as 别名]
# 或者: from string import atoi [as 别名]
def collect_memory_info():
'''
系统内存信息收集
'''
memory_buffer = {}
# 读取内存信息,并生成字典
with open("/proc/meminfo") as mem_file:
for line in mem_file:
# line:
# 'MemTotal: 16456100 kB'
# 过滤出所要信息
memory_buffer[line.split(':')[0]] = string.atoi(line.split(':')[1].split()[0])
mem_total = memory_buffer["MemTotal"]
mem_free = memory_buffer["MemFree"] + memory_buffer["Buffers"] + memory_buffer["Cached"]
mem_cache = memory_buffer["Cached"]
mem_info = {
"mem_total": mem_total,
"mem_free": mem_free,
"mem_cache": mem_cache
}
return mem_info
示例5: __init__
# 需要导入模块: import string [as 别名]
# 或者: from string import atoi [as 别名]
def __init__(self,sno,times,pkg_name):
# 打开待测应用,运行脚本,默认times为30次(可自己手动修改次数),获取该应用cpu、memory占用率的曲线图,图表保存至chart目录下
self.utils = AdbCmder()
self.sno = sno
if times is None or time == "":
self.times = 30 #top次数
else:
self.times = string.atoi(times)
if self.times < 15 and self.times > 0:
self.times = 20
if pkg_name is None or pkg_name == "":
self.pak_name = self.utils.get_current_package_name(sno)
else:
self.pkg_name = pkg_name # 设备当前运行应用的包名
# 获取cpu、mem占用
示例6: getOp
# 需要导入模块: import string [as 别名]
# 或者: from string import atoi [as 别名]
def getOp(self, tuple, engine):
from reportlab.lib.sequencer import getSequencer
import math
globalsequencer = getSequencer()
attr = self.attdict
try:
id = attr['id']
except KeyError:
id = None
try:
base = math.atoi(attr['base'])
except:
base=0
globalsequencer.reset(id, base)
self.op = ""
return ""
示例7: _PromptForSpreadsheet
# 需要导入模块: import string [as 别名]
# 或者: from string import atoi [as 别名]
def _PromptForSpreadsheet(self):
""" Prompts user to select spreadsheet.
Gets and displays titles of all spreadsheets for user to
select. Generic function taken from spreadsheetsExample.py.
Args:
none
Returns:
spreadsheet ID that the user selected: string
"""
feed = self.s_client.GetSpreadsheetsFeed()
self._PrintFeed(feed)
input = raw_input('\nSelection: ')
# extract and return the spreadsheet ID
return feed.entry[string.atoi(input)].id.text.rsplit('/', 1)[1]
示例8: __init__
# 需要导入模块: import string [as 别名]
# 或者: from string import atoi [as 别名]
def __init__(self, mmemory, typeaccess=0) :
if not isinstance(mmemory, Memory):
raise TypeError("ERREUR")
self.mmemory = mmemory
self.mmemory.open("r", typeaccess)
try :
fichier = open("/usr/include/asm/unistd.h", "r")
except IOError :
print "No such file /usr/include/asm/unistd.h"
sys.exit(-1)
liste = fichier.readlines()
fichier.close()
count = 0
for i in liste :
if(re.match("#define __NR_", i)) :
l = string.split(i)
if(l[2][0].isdigit()) :
count = string.atoi(l[2], 10)
self.lists_syscalls.append([count, l[1][5:]])
else :
count = count + 1
self.lists_syscalls.append([count, l[1][5:]])
示例9: strtoip
# 需要导入模块: import string [as 别名]
# 或者: from string import atoi [as 别名]
def strtoip(ipstr):
"""convert an IP address in string form to numeric."""
res = 0L
count = 0
n = string.split(ipstr, '.')
for i in n:
res = res << 8L
ot = string.atoi(i)
if ot < 0 or ot > 255:
raise ValueError, "invalid IP octet"
res = res + ot
count = count + 1
# could be incomplete (short); make it complete.
while count < 4:
res = res << 8L
count = count + 1
return res
示例10: cidrstrerr
# 需要导入模块: import string [as 别名]
# 或者: from string import atoi [as 别名]
def cidrstrerr(str):
"""Check an IP address or CIDR netblock for validity.
Returns None if it is and otherwise an error string."""
if not cvalid.match(str):
return 'Not a syntatically valid IP address or netblock'
rng = 32
pos = string.find(str, '/')
ips = str
if not pos == -1:
rng = string.atoi(ips[pos+1:])
ips = str[:pos]
if rng < 0 or rng > 32:
return 'CIDR length out of range'
n = string.split(ips, '.')
for i in n:
ip = string.atoi(i)
if (ip < 0 or ip > 255):
return 'an IP octet is out of range'
# could check to see if it is 'proper', but.
return None
示例11: __init__
# 需要导入模块: import string [as 别名]
# 或者: from string import atoi [as 别名]
def __init__(self, pos, offset, line):
"Initialize the synset from a line off a WN synset file."
self.pos = pos
"part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB."
self.offset = offset
"""integer offset into the part-of-speech file. Together
with pos, this can be used as a unique id."""
tokens = string.split(line[:string.index(line, '|')])
self.ssType = tokens[2]
self.gloss = string.strip(line[string.index(line, '|') + 1:])
self.lexname = Lexname.lexnames[int(tokens[1])]
(self._senseTuples, remainder) = _partition(tokens[4:], 2, string.atoi(tokens[3], 16))
(self._pointerTuples, remainder) = _partition(remainder[1:], 4, int(remainder[0]))
if pos == VERB:
(vfTuples, remainder) = _partition(remainder[1:], 3, int(remainder[0]))
def extractVerbFrames(index, vfTuples):
return tuple(map(lambda t:string.atoi(t[1]), filter(lambda t,i=index:string.atoi(t[2],16) in (0, i), vfTuples)))
senseVerbFrames = []
for index in range(1, len(self._senseTuples) + 1):
senseVerbFrames.append(extractVerbFrames(index, vfTuples))
self._senseVerbFrames = senseVerbFrames
self.verbFrames = tuple(extractVerbFrames(None, vfTuples))
"""A sequence of integers that index into
VERB_FRAME_STRINGS. These list the verb frames that any
Sense in this synset participates in. (See also
Sense.verbFrames.) Defined only for verbs."""
示例12: _wildcards
# 需要导入模块: import string [as 别名]
# 或者: from string import atoi [as 别名]
def _wildcards(self, response, match):
pos = string.find(response,'%')
while pos >= 0:
num = string.atoi(response[pos+1:pos+2])
response = response[:pos] + \
self._substitute(match.group(num)) + \
response[pos+2:]
pos = string.find(response,'%')
return response
示例13: _number
# 需要导入模块: import string [as 别名]
# 或者: from string import atoi [as 别名]
def _number(val):
try:
return string.atoi(val)
except:
return None
#
# timedelta
#
示例14: MakeNewBuildNo
# 需要导入模块: import string [as 别名]
# 或者: from string import atoi [as 别名]
def MakeNewBuildNo(project, buildDesc = None, auto=0, bRebrand = 0):
if buildDesc is None: buildDesc = "Created by Python"
ss = GetSS()
i = ss.VSSItem(project)
num = CountCheckouts(i)
if num > 0:
msg = "This project has %d items checked out\r\n\r\nDo you still want to continue?" % num
import win32ui
if win32ui.MessageBox(msg, project, win32con.MB_YESNO) != win32con.IDYES:
return
oldBuild = buildNo = GetLastBuildNo(project)
if buildNo is None:
buildNo = "1"
oldBuild = "<None>"
else:
try:
buildNo = string.atoi(buildNo)
if not bRebrand: buildNo = buildNo + 1
buildNo = str(buildNo)
except ValueError:
raise error("The previous label could not be incremented: %s" % (oldBuild))
if not auto:
from pywin.mfc import dialog
buildNo = dialog.GetSimpleInput("Enter new build number", buildNo, "%s - Prev: %s" % (project, oldBuild))
if buildNo is None: return
i.Label(buildNo, "Build %s: %s" % (buildNo,buildDesc))
if auto:
print "Branded project %s with label %s" % (project, buildNo)
return buildNo