当前位置: 首页>>代码示例>>Python>>正文


Python string.index方法代码示例

本文整理汇总了Python中string.index方法的典型用法代码示例。如果您正苦于以下问题:Python string.index方法的具体用法?Python string.index怎么用?Python string.index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在string的用法示例。


在下文中一共展示了string.index方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _testKeys

# 需要导入模块: import string [as 别名]
# 或者: from string import index [as 别名]
def _testKeys(self):
	"""Verify that index lookup can find each word in the index file."""
	print "Testing: ", self
	file = open(self.indexFile.file.name, _FILE_OPEN_MODE)
	counter = 0
	while 1:
	    line = file.readline()
	    if line == '': break
	    if line[0] != ' ':
		key = string.replace(line[:string.find(line, ' ')], '_', ' ')
		if (counter % 1000) == 0:
		    print "%s..." % (key,),
		    import sys
		    sys.stdout.flush()
		counter = counter + 1
		self[key]
	file.close()
	print "done." 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:20,代码来源:wordnet.py

示例2: _index

# 需要导入模块: import string [as 别名]
# 或者: from string import index [as 别名]
def _index(key, sequence, testfn=None, keyfn=None):
    """Return the index of key within sequence, using testfn for
    comparison and transforming items of sequence by keyfn first.
    
    >>> _index('e', 'hello')
    1
    >>> _index('E', 'hello', testfn=_equalsIgnoreCase)
    1
    >>> _index('x', 'hello')
    """
    index = 0
    for element in sequence:
	value = element
	if keyfn:
	    value = keyfn(value)
	if (not testfn and value == key) or (testfn and testfn(value, key)):
	    return index
	index = index + 1
    return None 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:21,代码来源:wordnet.py

示例3: do_call

# 需要导入模块: import string [as 别名]
# 或者: from string import index [as 别名]
def do_call(self, string):
        """
        Allows a C-like syntax for calling functions inside
        the target process (from his context).
        Example: call printf("yermom %d", 10)
        """
        self.trace.requireAttached()
        ind = string.index("(")
        if ind == -1:
            raise Exception('ERROR - call wants c-style syntax: ie call printf("yermom")')
        funcaddr = self.trace.parseExpression(string[:ind])

        try:
            args = eval(string[ind:])
        except:
            raise Exception('ERROR - call wants c-style syntax: ie call printf("yermom")')

        self.vprint("calling %s -> 0x%.8x" % (string[:ind], funcaddr))
        self.trace.call(funcaddr, args) 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:21,代码来源:__init__.py

示例4: _load_encoding

# 需要导入模块: import string [as 别名]
# 或者: from string import index [as 别名]
def _load_encoding(self):

        # map character code to bitmap index
        encoding = [None] * 256

        fp, format, i16, i32 = self._getformat(PCF_BDF_ENCODINGS)

        firstCol, lastCol = i16(fp.read(2)), i16(fp.read(2))
        firstRow, lastRow = i16(fp.read(2)), i16(fp.read(2))

        default = i16(fp.read(2))

        nencoding = (lastCol - firstCol + 1) * (lastRow - firstRow + 1)

        for i in range(nencoding):
            encodingOffset = i16(fp.read(2))
            if encodingOffset != 0xFFFF:
                try:
                    encoding[i+firstCol] = encodingOffset
                except IndexError:
                    break # only load ISO-8859-1 glyphs

        return encoding 
开发者ID:awslabs,项目名称:mxnet-lambda,代码行数:25,代码来源:PcfFontFile.py

示例5: count_frequency

# 需要导入模块: import string [as 别名]
# 或者: from string import index [as 别名]
def count_frequency(array):
    if not array: return None
    n = len(array)
    i = 0

    while i < n:
        if array[i] < 0:
            i += 1
            continue
        index = array[i] - 1
        if array[index] > 0:
            array[i] = array[index]
            array[index] = -1
        else:
            array[index] -= 1
            array[i] = 0
            i += 1
    return array 
开发者ID:UmassJin,项目名称:Leetcode,代码行数:20,代码来源:google面经集合.py

示例6: max_length_loop

# 需要导入模块: import string [as 别名]
# 或者: from string import index [as 别名]
def max_length_loop(array):
    def dfs(index, len):
        if visited[index]:
            result[0] = max(result[0], len-length[index])
            return 
        visited[index] = True
        length[index] = len
        dfs(array[index], len + 1)

    if not array:
        return 0
    n = len(array)
    visited = [False for _ in xrange(n)]
    length = [0 for _ in xrange(n)]
    result = [0]
    for i in xrange(n): # check each index in the array 
        dfs(i, 0)
    return result[0] 
开发者ID:UmassJin,项目名称:Leetcode,代码行数:20,代码来源:google面经集合.py

示例7: count_number

# 需要导入模块: import string [as 别名]
# 或者: from string import index [as 别名]
def count_number(array):
    if not array:
        return None
    count = 0; step = 1; number = array[0]
    index = 0
    result = []
    n = len(array)
    while index < n:
        count += step
        step *= 2
        if index + step >= n or array[index+step] != number:
            step = 1
            if index + step < n and array[index+step] != number:
                result.append((number, count))
                count = 0
                number = array[index+step]
        index += step
    result.append((number, count))
    return result 
开发者ID:UmassJin,项目名称:Leetcode,代码行数:21,代码来源:google面经集合.py

示例8: __getitem__

# 需要导入模块: import string [as 别名]
# 或者: from string import index [as 别名]
def __getitem__(self, index):
	return self.getSenses()[index] 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:4,代码来源:wordnet.py

示例9: __init__

# 需要导入模块: import string [as 别名]
# 或者: from string import index [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.""" 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:28,代码来源:wordnet.py

示例10: __nonzero__

# 需要导入模块: import string [as 别名]
# 或者: from string import index [as 别名]
def __nonzero__(self):
	"""Return false.  (This is to avoid scanning the whole index file
	to compute len when a Dictionary is used in test position.)
	
	>>> N and 'true'
	'true'
	"""
	return 1 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:10,代码来源:wordnet.py

示例11: __len__

# 需要导入模块: import string [as 别名]
# 或者: from string import index [as 别名]
def __len__(self):
	"""Return the number of index entries.
	
	>>> len(ADJ)
	21435
	"""
	if not hasattr(self, 'length'):
	    self.length = len(self.indexFile)
	return self.length 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:11,代码来源:wordnet.py

示例12: keys

# 需要导入模块: import string [as 别名]
# 或者: from string import index [as 别名]
def keys(self):
	"""Return a sorted list of strings that index words in this
	dictionary."""
	return self.indexFile.keys() 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:6,代码来源:wordnet.py

示例13: _indexFilePathname

# 需要导入模块: import string [as 别名]
# 或者: from string import index [as 别名]
def _indexFilePathname(filenameroot):
    if os.name in ('dos', 'nt'):
	path = os.path.join(WNSEARCHDIR, filenameroot + ".idx")
        if os.path.exists(path):
            return path
    return os.path.join(WNSEARCHDIR, "index." + filenameroot) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:8,代码来源:wordnet.py

示例14: __init__

# 需要导入模块: import string [as 别名]
# 或者: from string import index [as 别名]
def __init__(self, ctime, atime, mtime, filesize, allocsize, attribs, shortname, longname):
        self.__ctime = ctime
        self.__atime = atime
        self.__mtime = mtime
        self.__filesize = filesize
        self.__allocsize = allocsize
        self.__attribs = attribs
        try:
            self.__shortname = shortname[:string.index(shortname, '\0')]
        except ValueError:
            self.__shortname = shortname
        try:
            self.__longname = longname[:string.index(longname, '\0')]
        except ValueError:
            self.__longname = longname 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:17,代码来源:smb.py

示例15: _decode

# 需要导入模块: import string [as 别名]
# 或者: from string import index [as 别名]
def _decode(data, key):
    if '\245' in key:
        key2 = key[:string.index(key, '\245')+1]
    else:
        key2 = key
    if key2 in _decoder_table:
        decoder = _decoder_table[key2][0]
    else:
        decoder = _decode_default
    return decoder(data, key) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:12,代码来源:ic.py


注:本文中的string.index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。