本文整理匯總了Python中keyword.kwlist方法的典型用法代碼示例。如果您正苦於以下問題:Python keyword.kwlist方法的具體用法?Python keyword.kwlist怎麽用?Python keyword.kwlist使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在模塊keyword的用法示例。
在下文中一共展示了keyword.kwlist方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。
示例1: convert_param
點讚 6
# 需要導入模塊: import keyword [as 別名]
# 或者: from keyword import kwlist [as 別名]
def convert_param(method, param):
# remove notation, split by upper, convert to lowercase
param_sanitized = param.replace('*', '')
substr = param_sanitized
try:
substr = re.search('([A-Z]\w+)', param_sanitized).group(1)
except:
pass
case_re = re.compile(r'((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))')
converted_param = case_re.sub(r'_\1', substr).lower()
if converted_param in keyword.kwlist or converted_param in dir(__builtins__):
converted_param += '_param'
# check for duplicates. if seen, append number to end
if 'params' in method and len([param for param in method['params'] if param['name'] == converted_param]):
param_names = [param['name'] for param in method['params']]
for x in range(2, 10):
count_name = '{:s}{:d}'.format(converted_param, x)
if count_name not in param_names:
converted_param = count_name
break
return converted_param
開發者ID:fireeye,項目名稱:cWMI,代碼行數:23,
示例2: scanvars
點讚 6
# 需要導入模塊: import keyword [as 別名]
# 或者: from keyword import kwlist [as 別名]
def scanvars(reader, frame, locals):
"""Scan one logical line of Python and look up values of variables used."""
vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__
for ttype, token, start, end, line in tokenize.generate_tokens(reader):
if ttype == tokenize.NEWLINE: break
if ttype == tokenize.NAME and token not in keyword.kwlist:
if lasttoken == '.':
if parent is not __UNDEF__:
value = getattr(parent, token, __UNDEF__)
vars.append((prefix + token, prefix, value))
else:
where, value = lookup(token, frame, locals)
vars.append((token, where, value))
elif token == '.':
prefix += lasttoken + '.'
parent = value
else:
parent, prefix = None, ''
lasttoken = token
return vars
開發者ID:glmcdona,項目名稱:meddle,代碼行數:22,
示例3: global_matches
點讚 6
# 需要導入模塊: import keyword [as 別名]
# 或者: from keyword import kwlist [as 別名]
def global_ma