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


Python string.split方法代码示例

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


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

示例1: _initializePOSTables

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def _initializePOSTables():
    global _POSNormalizationTable, _POStoDictionaryTable
    _POSNormalizationTable = {}
    _POStoDictionaryTable = {}
    for pos, abbreviations in (
	    (NOUN, "noun n n."),
	    (VERB, "verb v v."),
	    (ADJECTIVE, "adjective adj adj. a s"),
	    (ADVERB, "adverb adv adv. r")):
	tokens = string.split(abbreviations)
	for token in tokens:
	    _POSNormalizationTable[token] = pos
	    _POSNormalizationTable[string.upper(token)] = pos
    for dict in Dictionaries:
	_POSNormalizationTable[dict] = dict.pos
	_POStoDictionaryTable[dict.pos] = dict 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:18,代码来源:wordnet.py

示例2: _parse_record

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def _parse_record(s):
    """
    Deprecated: use C{StandardFormat.fields()}
    
    @param s: toolbox record as a string
    @type  s: L{string}
    @rtype: iterator over L{list(string)}
    """

    s = "\n" + s                                         # Fields (even first) must start w/ a carriage return 
    if s.endswith("\n") : s = s[:-1]                     # Remove single extra carriage return
    for field in split(s, sep="\n\\")[1:] :              # Parse by carriage return followed by backslash
        parsed_field = split(field, sep=" ", maxsplit=1) # Split properly delineated field
        try :
            yield (parsed_field[0], parsed_field[1])
        except IndexError :
            yield (parsed_field[0], '') 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:19,代码来源:toolbox.py

示例3: _substitute

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def _substitute(self, str):
        """
        Substitute words in the string, according to the specified reflections,
        e.g. "I'm" -> "you are"
        
        @type str: C{string}
        @param str: The string to be mapped
        @rtype: C{string}
        """

        words = ""
        for word in string.split(string.lower(str)):
            if self._reflections.has_key(word):
                word = self._reflections[word]
            words += ' ' + word
        return words 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:18,代码来源:__init__.py

示例4: type_identityref_values

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def type_identityref_values(self, t):
        base_idn = t.search_one('base')
        if base_idn:
            # identity has a base
            idn_key = None
            base_idns = base_idn.arg.split(':')
            if len(base_idns) > 1:
                for module in self.module_prefixes:
                    if base_idns[0] == self.module_prefixes[module][0]:
                        idn_key = module + ':' + base_idns[1]
                        break
            else:
                idn_key = self.name + ':' + base_idn.arg

            if idn_key is None:
                return ''

            value_stmts = []
            stmts = self.identity_deps.get(idn_key, [])
            for value in stmts:
                ids = value.split(':')
                value_stmts.append(self.module_prefixes[ids[0]][0] + ':' + ids[1])
            if stmts:
                return '|'.join(sorted(value_stmts))
        return '' 
开发者ID:CiscoDevNet,项目名称:yang-explorer,代码行数:27,代码来源:cxml.py

示例5: version_checker

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def version_checker(cur_ver,ref_ver):
	"""
	Checks version in major/minor format of a current version versus a reference version.
	Supports 2 or more level versioning, only 2 levels checked)

	Input:
	cur_ver: float or string of version to check
	ref_ver: float or string of reference version

	Returns:
	bool for pass or fail
	"""
	cur_ver = str(cur_ver)
	ref_ver = str(ref_ver)
	cur_Varr = [int(vvv) for vvv in cur_ver.split('.')[0:2]]
	cur_V = cur_Varr[0]*10**2 + cur_Varr[1]%100
	ref_Varr = [int(vvv) for vvv in ref_ver.split('.')[0:2]]
	ref_V = ref_Varr[0]*10**2 + ref_Varr[1]%100
	if cur_V > ref_V: return True
	return False

#Run dependency check 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:24,代码来源:meica.py

示例6: ParseMetricFile

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def ParseMetricFile(file_name, metric_column):
  """
  Convert a metrics file into a set of numbers.
  This returns a sorted list of tuples with the first number
  being from the first column (bitrate) and the second being from
  metric_column (counting from 0).
  """
  metric_set1 = set([])
  metric_file = open(file_name, "r")
  for line in metric_file:
    metrics = string.split(line)
    if HasMetrics(line):
      if metric_column < len(metrics):
        my_tuple = float(metrics[0]), float(metrics[metric_column])
      else:
        my_tuple = float(metrics[0]), 0
      metric_set1.add(my_tuple)
  metric_set1_sorted = sorted(metric_set1)
  return metric_set1_sorted 
开发者ID:google,项目名称:compare-codecs,代码行数:21,代码来源:visual_metrics.py

示例7: main

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def main():
    print "This program converts a sequence of ASCII numbers into"
    print "the string of text that it represents."
    print
    
    inString = raw_input("Please enter the ASCII-encoded message: ")

    message = []
    for numStr in string.split(inString):
        asciiNum = eval(numStr) 
        message1 = ord(asciiNum)          # convert digits to a number
        message.append(message1)

    print message
        
    print "The decoded message is:","".join(message) 
开发者ID:sai29,项目名称:Python-John-Zelle-book,代码行数:18,代码来源:1.py

示例8: round_sig_error

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def round_sig_error(x, ex, n, paren=False):
   '''Find ex rounded to n sig-figs and make the floating point x
   match the number of decimals.  If [paren], the string is
   returned as quantity(error) format'''
   stex = round_sig(ex,n)
   if stex.find('.') < 0:
      extra_zeros = len(stex) - n
      sigfigs = len(str(int(x))) - extra_zeros
      stx = round_sig(x,sigfigs)
   else:
      num_after_dec = len(string.split(stex,'.')[1])
      stx = ("%%.%df" % num_after_dec) % (x)
   if paren:
      if stex.find('.') >= 0:
         stex = stex[stex.find('.')+1:]
      return "%s(%s)" % (stx,stex)
   return stx,stex 
开发者ID:geomagpy,项目名称:magpy,代码行数:19,代码来源:sigfig.py

示例9: round_sig_error2

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def round_sig_error2(x, ex1, ex2, n):
   '''Find min(ex1,ex2) rounded to n sig-figs and make the floating point x
   and max(ex,ex2) match the number of decimals.'''
   minerr = min(ex1,ex2)
   minstex = round_sig(minerr,n)
   if minstex.find('.') < 0:
      extra_zeros = len(minstex) - n
      sigfigs = len(str(int(x))) - extra_zeros
      stx = round_sig(x,sigfigs)
      maxstex = round_sig(max(ex1,ex2),sigfigs)
   else:
      num_after_dec = len(string.split(minstex,'.')[1])
      stx = ("%%.%df" % num_after_dec) % (x)
      maxstex = ("%%.%df" % num_after_dec) % (max(ex1,ex2))
   if ex1 < ex2:
      return stx,minstex,maxstex
   else:
      return stx,maxstex,minstex 
开发者ID:geomagpy,项目名称:magpy,代码行数:20,代码来源:sigfig.py

示例10: encode_name

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def encode_name(name, type, scope):
    if name == '*':
        name += '\0' * 15
    elif len(name) > 15:
        name = name[:15] + chr(type)
    else:
        name = string.ljust(name, 15) + chr(type)

    encoded_name = chr(len(name) * 2) + re.sub('.', _do_first_level_encoding, name)
    if scope:
        encoded_scope = ''
        for s in string.split(scope, '.'):
            encoded_scope = encoded_scope + chr(len(s)) + s
        return encoded_name + encoded_scope + '\0'
    else:
        return encoded_name.encode('ascii') + '\0'

# Internal method for use in encode_name() 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:20,代码来源:nmb.py

示例11: _extract_authdata

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def _extract_authdata(item):
    '''
    Extract version, authority tag, and authority data from a single array item of AuthenticationAuthority

    item
        The NSString instance representing the authority string

    returns
        version (default 1.0.0), tag, data as a tuple
    '''
    parts = string.split(item, ';', 2)

    if not parts[0]:
        parts[0] = '1.0.0'

    return {
        'version': parts[0],
        'tag': parts[1],
        'data': parts[2]
    } 
开发者ID:mosen,项目名称:salt-osx,代码行数:22,代码来源:mac_shadow.py

示例12: get_build_version

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def get_build_version():
    """Return the version of MSVC that was used to build Python.

    For Python 2.3 and up, the version number is included in
    sys.version.  For earlier versions, assume the compiler is MSVC 6.
    """

    prefix = "MSC v."
    i = string.find(sys.version, prefix)
    if i == -1:
        return 6
    i = i + len(prefix)
    s, rest = sys.version[i:].split(" ", 1)
    majorVersion = int(s[:-2]) - 6
    minorVersion = int(s[2:3]) / 10.0
    # I don't think paths are affected by minor version in version 6
    if majorVersion == 6:
        minorVersion = 0
    if majorVersion >= 6:
        return majorVersion + minorVersion
    # else we don't know what version of the compiler this is
    return None 
开发者ID:glmcdona,项目名称:meddle,代码行数:24,代码来源:msvccompiler.py

示例13: find_exe

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def find_exe(self, exe):
        """Return path to an MSVC executable program.

        Tries to find the program in several places: first, one of the
        MSVC program search paths from the registry; next, the directories
        in the PATH environment variable.  If any of those work, return an
        absolute path that is known to exist.  If none of them work, just
        return the original program name, 'exe'.
        """

        for p in self.__paths:
            fn = os.path.join(os.path.abspath(p), exe)
            if os.path.isfile(fn):
                return fn

        # didn't find it; try existing path
        for p in string.split(os.environ['Path'],';'):
            fn = os.path.join(os.path.abspath(p),exe)
            if os.path.isfile(fn):
                return fn

        return exe 
开发者ID:glmcdona,项目名称:meddle,代码行数:24,代码来源:msvccompiler.py

示例14: _format_changelog

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def _format_changelog(self, changelog):
        """Format the changelog correctly and convert it to a list of strings
        """
        if not changelog:
            return changelog
        new_changelog = []
        for line in string.split(string.strip(changelog), '\n'):
            line = string.strip(line)
            if line[0] == '*':
                new_changelog.extend(['', line])
            elif line[0] == '-':
                new_changelog.append(line)
            else:
                new_changelog.append('  ' + line)

        # strip trailing newline inserted by first changelog entry
        if not new_changelog[0]:
            del new_changelog[0]

        return new_changelog

    # _format_changelog()

# class bdist_rpm 
开发者ID:glmcdona,项目名称:meddle,代码行数:26,代码来源:bdist_rpm.py

示例15: source_synopsis

# 需要导入模块: import string [as 别名]
# 或者: from string import split [as 别名]
def source_synopsis(file):
    line = file.readline()
    while line[:1] == '#' or not strip(line):
        line = file.readline()
        if not line: break
    line = strip(line)
    if line[:4] == 'r"""': line = line[1:]
    if line[:3] == '"""':
        line = line[3:]
        if line[-1:] == '\\': line = line[:-1]
        while not strip(line):
            line = file.readline()
            if not line: break
        result = strip(split(line, '"""')[0])
    else: result = None
    return result 
开发者ID:glmcdona,项目名称:meddle,代码行数:18,代码来源:pydoc.py


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