• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python string.endswith函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _find_fstring_string

def _find_fstring_string(endpats, fstring_stack, line, lnum, pos):
    tos = fstring_stack[-1]
    allow_multiline = tos.allow_multiline()
    if allow_multiline:
        match = fstring_string_multi_line.match(line, pos)
    else:
        match = fstring_string_single_line.match(line, pos)
    if match is None:
        return tos.previous_lines, pos

    if not tos.previous_lines:
        tos.last_string_start_pos = (lnum, pos)

    string = match.group(0)
    for fstring_stack_node in fstring_stack:
        end_match = endpats[fstring_stack_node.quote].match(string)
        if end_match is not None:
            string = end_match.group(0)[:-len(fstring_stack_node.quote)]

    new_pos = pos
    new_pos += len(string)
    if allow_multiline and (string.endswith('\n') or string.endswith('\r')):
        tos.previous_lines += string
        string = ''
    else:
        string = tos.previous_lines + string

    return string, new_pos
开发者ID:PKpacheco,项目名称:monitor-dollar-value-galicia,代码行数:28,代码来源:tokenize.py


示例2: is_multiline_start

    def is_multiline_start(self, string):
        start_quote = False
        end_quote = False

        if string.startswith('"') and not string.startswith('"""'):
            start_quote = True
        if string.endswith('"') and not string.endswith('"""'):
            end_quote = True

        # line that only contains a quote
        if len(string.strip()) == 1 and (start_quote or end_quote):
            return True

        return start_quote and (start_quote and not end_quote)
开发者ID:mahmoodi,项目名称:refinery-platform,代码行数:14,代码来源:isa_tab_parser.py


示例3: rtrim

def rtrim(string, suffix):
    ''' Trim all suffixes from string. '''

    length = len(suffix)
    while string.endswith(suffix):
        string = string[:-length]
    return string
开发者ID:goodcrypto,项目名称:goodcrypto-libs,代码行数:7,代码来源:utils.py


示例4: getCryptUrl

 def getCryptUrl(self, string):
     if string.find("?") < 0:
         string += "?"
     if not string.endswith("?"):
         string += "&"
     string += "cyt=1"
     return string
开发者ID:AngelClover,项目名称:libMA,代码行数:7,代码来源:CryptUtils.py


示例5: unQuote

        def unQuote(string):
            """
            @param string:
            @type string:

            @return: The stripped string.
            @rtype: string
            """

            if string.startswith('"') and string.endswith('"'):
                string = string[1:-1]
                
            elif string.startswith("'") and string.endswith("'"):
                string = string[1:-1]

            return string
开发者ID:MokaCreativeLLC,项目名称:XNATSlicer,代码行数:16,代码来源:MokaUtils.py


示例6: remove_punctuation

def remove_punctuation(word_list):

    for each_word in word_list:
        print type(each_word)

        if string.endswith("!"):
           word_list[each_word]=word_list[each_word].rstrip()
开发者ID:laurenchow,项目名称:Exercise-7,代码行数:7,代码来源:new_wordcount_funct.py


示例7: _find_fstring_string

def _find_fstring_string(fstring_stack, line, lnum, pos):
    tos = fstring_stack[-1]
    if tos.is_in_expr():
        return '', pos
    else:
        new_pos = pos
        allow_multiline = tos.allow_multiline()
        if allow_multiline:
            match = fstring_string_multi_line.match(line, pos)
        else:
            match = fstring_string_single_line.match(line, pos)
        if match is None:
            string = tos.previous_lines
        else:
            if not tos.previous_lines:
                tos.last_string_start_pos = (lnum, pos)

            string = match.group(0)
            for fstring_stack_node in fstring_stack:
                try:
                    string = string[:string.index(fstring_stack_node.quote)]
                except ValueError:
                    pass  # The string was not found.

            new_pos += len(string)
            if allow_multiline and string.endswith('\n'):
                tos.previous_lines += string
                string = ''
            else:
                string = tos.previous_lines + string

        return string, new_pos
开发者ID:andrewgu12,项目名称:config,代码行数:32,代码来源:tokenize.py


示例8: getEmail

def getEmail(url):
	try:
		tokens=getHTML(url)
		contacts=[]
		for i in range(0,len(tokens)):
			if "@" in tokens[i]:
				string= str(tokens[i-1])
				if string[0].isalpha():
					string = string +str(tokens[i])
					string = string +str(tokens[i+1])
					endA=str(tokens[i+1])
					if endA.find(".")>=0:
						if is_in_arr(contacts,tokens[i])==False:
							if string.endswith(".")==False:
								contacts.append(string)
			if "at"==tokens[i]:
				if tokens[i-1]=="[" and tokens[i+1]=="]":
					string=str(tokens[i-2])+"@"+str(tokens[i+2])
					contacts.append(string)
			if len(tokens[i])==3:
				if tokens[i].isalpha==False:
					if (tokens[i+1].isalpha==False and len(tokens[i+1])==3) and (tokens[i+2].isalpha()==False and len(tokens[i+2])==3) and item not in contacts:
						string = str(tokens[i]) +str(tokens[i+1])+str(tokens[i+2])
						contacts.append("Email: "+string)
		new = deleteDuplicates(contacts)
		return new
	except:
		return "Error Occured"
开发者ID:drat,项目名称:ScrapeC,代码行数:28,代码来源:scrape.py


示例9: string_remove_quotes

def string_remove_quotes(string):
    if type(string) not in (str, unicode):
        return string

    for char in ('"', "'"):
        if string.startswith(char) and string.endswith(char):
            return string[1:-1]
开发者ID:Cybolic,项目名称:vineyard,代码行数:7,代码来源:util.py


示例10: chomp_string

def chomp_string(string, postfix):
    """Chomps the given string off of the end of the given string, if
    the string is long enough and the character is there
    otherwise is doesn't touch the string"""
    if string.endswith(postfix):
        up_to_postfix = len(string) - len(postfix)
        string = string[:up_to_postfix]
    return string
开发者ID:kyledewey,项目名称:Notes-to-Google-Sites,代码行数:8,代码来源:notes_parser.py


示例11: remove_punct

def remove_punct(string):
    """Remove common punctuation marks."""
    if string.endswith('?'):
        string = string[:-1]
    return (string.replace(',', '')
            .replace('.', '')
            .replace(';', '')
            .replace('!', ''))
开发者ID:carriercomm,项目名称:Counselor_bot,代码行数:8,代码来源:therapist.py


示例12: remove_punct

def remove_punct(string):

    if string.endswith('?'):
        string = string[:-1]
    return (string.replace(',', '')
            .replace(',', '')
            .replace(';', '')
            .replace('!', ''))
开发者ID:sotlampr,项目名称:cv_bot,代码行数:8,代码来源:assistant.py


示例13: hey

def hey (string):
    if string.isspace() or string == "":
        return "Fine. Be that way!"
    elif string.isupper():
        return "Whoa, chill out!"
    elif string.endswith("?"):
        return "Sure."
    else:
        return "Whatever."
开发者ID:itsolutionscorp,项目名称:AutoStyle-Clustering,代码行数:9,代码来源:0e104d6d8b4c40058238440191ffa8a8.py


示例14: strip_trailing_slash

 def strip_trailing_slash(string):
     """
     If the string has a trailing '/', removes it
     :param string: string to check
     :return: string without a trailing '/'
     :rtype: string
     """
     if string.endswith('/'):
         return string[:-1]
     return string
开发者ID:AlmavivA,项目名称:stratos,代码行数:10,代码来源:cartridgeagentutils.py


示例15: endswith

    def endswith(self, string, suffix, msg=None):
        """
        Asserts that first string ends with the second suffix

        :Args:
         - String to test
         - String suffix should be at the end of the string
         - Message that will be printed if it fails
        """

        assert string.endswith(suffix), msg
开发者ID:AutomatedTester,项目名称:unittest-zero,代码行数:11,代码来源:unittestzero.py


示例16: dequote

def dequote(string):
    """Takes string which may or may not be quoted and unquotes it.

    It only considers double quotes. This function does NOT consider
    parenthised lists to be quoted.
    """
    if string and string.startswith('"') and string.endswith('"'):
        string = string[1:-1]  # Strip off the surrounding quotes.
        string = string.replace('\\"', '"')
        string = string.replace('\\\\', '\\')
    return string
开发者ID:dimpase,项目名称:offlineimap,代码行数:11,代码来源:imaputil.py


示例17: remove_suffix

def remove_suffix(string, suffix):
    """
    This funtion removes the given suffix from a string, if the string
    does indeed end with the prefix; otherwise, it returns the string
    unmodified.
    """
    # Special case: if suffix is empty, string[:0] returns ''. So, test
    # for a non-empty suffix.
    if suffix and string.endswith(suffix):
        return string[:-len(suffix)]
    else:
        return string
开发者ID:Active8-BV,项目名称:cryptobox_app,代码行数:12,代码来源:hookutils.py


示例18: string_safe_shell

def string_safe_shell(string):
    if string.startswith("'") and string.endswith("'"):
        return string
    else:
        return string_escape_char(
            string,
            str(
                '&();|\n'+  # Control operators
                '<>'+       # Redirection operators
                '!*?[]'+    # Shell patterns
                '$'         # Variables
            )
        )
开发者ID:Cybolic,项目名称:vineyard,代码行数:13,代码来源:util.py


示例19: trim

def trim(string, xfix):
    ''' Trim all prefixes or suffixes of xfix from string. '''

    if is_string(string):
        string = string.encode()
    if is_string(xfix):
        xfix = xfix.encode()

    length = len(xfix)
    while string.startswith(xfix):
        string = string[length:]
    while string.endswith(xfix):
        string = string[:-length]
    return string
开发者ID:goodcrypto,项目名称:goodcrypto-libs,代码行数:14,代码来源:utils.py


示例20: _innerize_selected_string

def _innerize_selected_string(editor):
    '''Given that a string is selected, select only its contents.'''
    assert isinstance(editor, wingapi.CAPIEditor)
    selection_start, selection_end = editor.GetSelection()
    string = editor.GetDocument().GetCharRange(selection_start, selection_end)
    match = string_pattern.match(string)
    assert match
    delimiter = match.group('delimiter')
    prefix = match.group('prefix')
    fixed_start = selection_start + len(delimiter) + len(prefix)
    fixed_end = selection_end - len(delimiter) if string.endswith(delimiter) \
                                                             else selection_end
    editor.SetSelection(fixed_start, fixed_end)                               
        
    
开发者ID:cool-RR,项目名称:cute-wing-stuff,代码行数:13,代码来源:string_selecting.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python string.expandtabs函数代码示例发布时间:2022-05-27
下一篇:
Python string.encode函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap