本文整理汇总了Python中string.endswith函数的典型用法代码示例。如果您正苦于以下问题:Python endswith函数的具体用法?Python endswith怎么用?Python endswith使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了endswith函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例3: rtrim
def rtrim(string, suffix):
''' Trim all suffixes from string. '''
length = len(suffix)
while string.endswith(suffix):
string = string[:-length]
return string
示例4: getCryptUrl
def getCryptUrl(self, string):
if string.find("?") < 0:
string += "?"
if not string.endswith("?"):
string += "&"
string += "cyt=1"
return string
示例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
示例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()
示例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
示例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"
示例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]
示例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
示例11: remove_punct
def remove_punct(string):
"""Remove common punctuation marks."""
if string.endswith('?'):
string = string[:-1]
return (string.replace(',', '')
.replace('.', '')
.replace(';', '')
.replace('!', ''))
示例12: remove_punct
def remove_punct(string):
if string.endswith('?'):
string = string[:-1]
return (string.replace(',', '')
.replace(',', '')
.replace(';', '')
.replace('!', ''))
示例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."
示例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
示例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