當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。