本文整理汇总了Python中string.startswith函数的典型用法代码示例。如果您正苦于以下问题:Python startswith函数的具体用法?Python startswith怎么用?Python startswith使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了startswith函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: color
def color(string, color=None):
"""
Change text color for the Linux terminal.
"""
attr = []
# bold
attr.append("1")
if color:
if color.lower() == "red":
attr.append("31")
elif color.lower() == "green":
attr.append("32")
elif color.lower() == "blue":
attr.append("34")
return "\x1b[%sm%s\x1b[0m" % (";".join(attr), string)
else:
if string.startswith("[!]"):
attr.append("31")
return "\x1b[%sm%s\x1b[0m" % (";".join(attr), string)
elif string.startswith("[+]"):
attr.append("32")
return "\x1b[%sm%s\x1b[0m" % (";".join(attr), string)
elif string.startswith("[*]"):
attr.append("34")
return "\x1b[%sm%s\x1b[0m" % (";".join(attr), string)
else:
return string
开发者ID:haylesr,项目名称:Empire,代码行数:30,代码来源:helpers.py
示例2: color
def color(string, color=None):
"""
Change text color for the Linux terminal.
"""
attr = []
# bold
attr.append('1')
if color:
if color.lower() == "red":
attr.append('31')
elif color.lower() == "yellow":
attr.append('33')
elif color.lower() == "green":
attr.append('32')
elif color.lower() == "blue":
attr.append('34')
return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), string)
else:
if string.startswith("[!]"):
attr.append('31')
return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), string)
elif string.startswith("[+]"):
attr.append('32')
return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), string)
elif string.startswith("[*]"):
attr.append('34')
return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), string)
else:
return string
开发者ID:0x0mar,项目名称:EmPyre,代码行数:32,代码来源:helpers.py
示例3: color
def color(string, color='', graphic=''):
"""
Change text color for the Linux terminal.
Args:
string (str): String to colorify
color (str): Color to colorify the string in the following list:
black, red, green, yellow, blue, purple, cyan, gr[ae]y
graphic (str): Graphic to append to the beginning of the line
"""
if not color:
if string.startswith("[!] "):
color = 'red'
elif string.startswith("[+] "):
color = 'green'
elif string.startswith("[*] "):
color = 'blue'
else:
color = 'normal'
if color not in colors:
print(colors['red'] + 'Color not found: {}'.format(color) + colors['normal'])
return
if color:
return colors[color] + graphic + string + colors['normal']
else:
return string + colors['normal']
开发者ID:Exploit-install,项目名称:pentestly,代码行数:30,代码来源:smbmap.py
示例4: expand_tilde
def expand_tilde(string):
"""
Return an expanded version of the string by replacing a leading tilde
with %HOME% (if defined) or %USERPROFILE%.
"""
if 'HOME' in os.environ.keys():
home_var = 'HOME'
else:
home_var = 'USERPROFILE'
if string.startswith('~') or string.startswith('"~'):
string = string.replace('~', '%' + home_var + '%', 1)
return string
开发者ID:juntalis,项目名称:pycmd-fork,代码行数:12,代码来源:common.py
示例5: cleanExtension
def cleanExtension(string):
"""
@param string: The extension to clean
@type string: str
@return: The cleaned extension in <i>.ext</i> format.
@rtype: str
"""
if string.startswith('*'):
string = string[1:]
if not string.startswith('.'):
string = '.' + string
return string
开发者ID:MokaCreativeLLC,项目名称:XNATSlicer,代码行数:13,代码来源:MokaUtils.py
示例6: 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
示例7: 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
示例8: _check_conflict
def _check_conflict(self, option):
conflict_opts = []
for opt in option._short_opts:
if self._short_opt.has_key(opt):
conflict_opts.append((opt, self._short_opt[opt]))
for opt in option._long_opts:
if self._long_opt.has_key(opt):
conflict_opts.append((opt, self._long_opt[opt]))
if conflict_opts:
handler = self.conflict_handler
if handler == "error":
opts = []
for co in conflict_opts:
opts.append(co[0])
raise errors.OptionConflictError(
"conflicting option string(s): %s"
% string.join(opts, ", "),
option)
elif handler == "resolve":
for (opt, c_option) in conflict_opts:
if string.startswith(opt, "--"):
c_option._long_opts.remove(opt)
del self._long_opt[opt]
else:
c_option._short_opts.remove(opt)
del self._short_opt[opt]
if not (c_option._short_opts or c_option._long_opts):
c_option.container.option_list.remove(c_option)
开发者ID:develersrl,项目名称:pyuac,代码行数:29,代码来源:option_parser.py
示例9: 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
示例10: decode
def decode(cls, string, base):
"""
Decode a Base X encoded string into a decimal number
@param string: The encoded number, in str format
@param base: The base from which to convert the number
@return : Number in decimal encoding
@rvalue : int
"""
if base < 2 or base > 62:
raise ValueError('Illegal base')
num = 0
# If ``string`` is padded with zeros, remove them
while 1:
if string != '0' and string.startswith('0'):
string = string[1:]
else:
break
for power, char in enumerate(string[::-1]):
try:
index = cls.ALPHABET.index(char)
except ValueError:
# ``char`` is not contained in the alphabet
raise ValueError('Number contains illegal digits')
if index >= base:
raise ValueError('Number contains illegal digits')
num += index * (base ** power)
return num
开发者ID:stargazer,项目名称:baseX-py,代码行数:35,代码来源:x.py
示例11: ltrim
def ltrim(string, prefix):
''' Trim all prefixes from string. '''
length = len(prefix)
while string.startswith(prefix):
string = string[length:]
return string
开发者ID:goodcrypto,项目名称:goodcrypto-libs,代码行数:7,代码来源:utils.py
示例12: fromPDBrecord
def fromPDBrecord(cls,string):
if string.startswith('ATOM'):
name = string[12:16].strip()
x = float(string[30:38].strip())
y = float(string[38:46].strip())
z = float(string[46:54].strip())
return cls(name,[x,y,z])
else:
sys.exit(1)
开发者ID:jeffhammond,项目名称:nwchem,代码行数:9,代码来源:myatom.py
示例13: color
def color(string, color='', graphic=''):
"""
Change text color for the Linux terminal.
Args:
string (str): String to colorify
color (str): Color to colorify the string in the following list:
black, red, green, yellow, blue, purple, cyan, gr[ae]y
graphic (str): Graphic to append to the beginning of the line
"""
colors = {
'normal' : "\x1b[0m",
'black' : "\x1b[30m",
'red' : "\x1b[31m",
'green' : "\x1b[32m",
'yellow' : "\x1b[33m",
'blue' : "\x1b[34m",
'purple' : "\x1b[35m",
'cyan' : "\x1b[36m",
'grey' : "\x1b[90m",
'gray' : "\x1b[90m",
'bold' : "\x1b[1m"
}
if not color:
if string.startswith("[!] "):
color = 'red'
elif string.startswith("[+] "):
color = 'green'
elif string.startswith("[*] "):
color = 'blue'
else:
color = 'normal'
if color not in colors:
print colors['red'] + 'Color not found: {}'.format(color) + colors['normal']
return
if color:
return colors[color] + graphic + string + colors['normal']
else:
return string + colors['normal']
开发者ID:ctfhacker,项目名称:Empire,代码行数:43,代码来源:helpers.py
示例14: remove_prefix
def remove_prefix(string, prefix):
"""
This funtion removes the given prefix from a string, if the string does
indeed begin with the prefix; otherwise, it returns the string
unmodified.
"""
if string.startswith(prefix):
return string[len(prefix):]
else:
return string
开发者ID:Active8-BV,项目名称:cryptobox_app,代码行数:10,代码来源:hookutils.py
示例15: lchop
def lchop(string, prefix):
"""Removes a prefix from string
:param string: String, possibly prefixed with prefix
:param prefix: Prefix to remove from string
:returns: string without the prefix
"""
if string.startswith(prefix):
return string[len(prefix):]
return string
开发者ID:enkore,项目名称:i3pystatus,代码行数:10,代码来源:util.py
示例16: set_usage
def set_usage(self, usage):
if usage is None:
self.usage = _("%prog [options]")
elif usage is SUPPRESS_USAGE:
self.usage = None
# For backwards compatibility with Optik 1.3 and earlier.
elif string.startswith(usage, "usage:" + " "):
self.usage = usage[7:]
else:
self.usage = usage
开发者ID:develersrl,项目名称:pyuac,代码行数:10,代码来源:option_parser.py
示例17: 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
示例18: find_in_bor
def find_in_bor(root, string):
#print string
if string == 'le':
for i in range(len(root.arr)):
print root.arr[i].string
for i in range(len(root.arr)):
if root.arr[i].string == string:
return True if root.arr[i].is_leaf else False;
elif string.startswith(root.arr[i].string):
return find_in_bor(root.arr[i], string[len(root.arr[i].string):])
return False
开发者ID:alex0parhomenko,项目名称:technosfera,代码行数:12,代码来源:mis_fix.py
示例19: 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
示例20: safe_prepend
def safe_prepend(prepend_string, string):
"""Prepend to string non-destructively
Ex: safe_prepend('EUCTR', 'EUCTR12345678') => 'EUCTR12345678'
Args:
prepend_string: string to prepend
string: string to prepend to
"""
if string is None:
return None
if not string.startswith(prepend_string):
string = '%s%s' % (prepend_string, string)
return string
开发者ID:opentrials,项目名称:processors,代码行数:14,代码来源:__init__.py
注:本文中的string.startswith函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论