本文整理汇总了Python中keyword.kwlist方法的典型用法代码示例。如果您正苦于以下问题:Python keyword.kwlist方法的具体用法?Python keyword.kwlist怎么用?Python keyword.kwlist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keyword
的用法示例。
在下文中一共展示了keyword.kwlist方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_param
# 需要导入模块: 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
示例2: scanvars
# 需要导入模块: 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
示例3: global_matches
# 需要导入模块: import keyword [as 别名]
# 或者: from keyword import kwlist [as 别名]
def global_matches(self, text):
"""Compute matches when text is a simple name.
Return a list of all keywords, built-in functions and names currently
defined in self.namespace that match.
"""
import keyword
matches = []
n = len(text)
for word in keyword.kwlist:
if word[:n] == text:
matches.append(word)
for nspace in [__builtin__.__dict__, self.namespace]:
for word, val in nspace.items():
if word[:n] == text and word != "__builtins__":
matches.append(self._callable_postfix(val, word))
return matches
示例4: global_matches
# 需要导入模块: import keyword [as 别名]
# 或者: from keyword import kwlist [as 别名]
def global_matches(self, text):
"""Compute matches when text is a simple name.
Return a list of all keywords, built-in functions and names currently
defined in self.namespace that match.
"""
import keyword
matches = []
seen = {"__builtins__"}
n = len(text)
for word in keyword.kwlist:
if word[:n] == text:
seen.add(word)
matches.append(word)
for nspace in [self.namespace, __builtin__.__dict__]:
for word, val in nspace.items():
if word[:n] == text and word not in seen:
seen.add(word)
matches.append(self._callable_postfix(val, word))
return matches
示例5: global_matches
# 需要导入模块: import keyword [as 别名]
# 或者: from keyword import kwlist [as 别名]
def global_matches(self, text):
"""Compute matches when text is a simple name.
Return a list of all keywords, built-in functions and names currently
defined in self.namespace that match.
"""
import keyword
matches = []
seen = {"__builtins__"}
n = len(text)
for word in keyword.kwlist:
if word[:n] == text:
seen.add(word)
matches.append(word)
for nspace in [self.namespace, builtins.__dict__]:
for word, val in nspace.items():
if word[:n] == text and word not in seen:
seen.add(word)
matches.append(self._callable_postfix(val, word))
return matches
示例6: make_pat
# 需要导入模块: import keyword [as 别名]
# 或者: from keyword import kwlist [as 别名]
def make_pat():
kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b"
builtinlist = [str(name) for name in dir(__builtin__)
if not name.startswith('_')]
# self.file = file("file") :
# 1st 'file' colorized normal, 2nd as builtin, 3rd as string
builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b"
comment = any("COMMENT", [r"#[^\n]*"])
stringprefix = r"(\br|u|ur|R|U|UR|Ur|uR|b|B|br|Br|bR|BR)?"
sqstring = stringprefix + r"'[^'\\\n]*(\\.[^'\\\n]*)*'?"
dqstring = stringprefix + r'"[^"\\\n]*(\\.[^"\\\n]*)*"?'
sq3string = stringprefix + r"'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
dq3string = stringprefix + r'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
string = any("STRING", [sq3string, dq3string, sqstring, dqstring])
return kw + "|" + builtin + "|" + comment + "|" + string +\
"|" + any("SYNC", [r"\n"])
示例7: global_matches
# 需要导入模块: import keyword [as 别名]
# 或者: from keyword import kwlist [as 别名]
def global_matches(self, text):
"""Compute matches when text is a simple name.
Return a list of all keywords, built-in functions and names currently
defined in self.namespace or self.global_namespace that match.
"""
#print 'Completer->global_matches, txt=%r' % text # dbg
matches = []
match_append = matches.append
n = len(text)
for lst in [keyword.kwlist,
__builtin__.__dict__.keys(),
self.namespace.keys(),
self.global_namespace.keys()]:
for word in lst:
if word[:n] == text and word != "__builtins__":
match_append(word)
return matches
示例8: make_pat
# 需要导入模块: import keyword [as 别名]
# 或者: from keyword import kwlist [as 别名]
def make_pat():
kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b"
builtinlist = [str(name) for name in dir(__builtin__)
if not name.startswith('_')]
# We don't know whether "print" is a function or a keyword,
# so we always treat is as a keyword (the most common case).
builtinlist.remove('print')
# self.file = file("file") :
# 1st 'file' colorized normal, 2nd as builtin, 3rd as string
builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b"
comment = any("COMMENT", [r"#[^\n]*"])
stringprefix = r"(\br|u|ur|R|U|UR|Ur|uR|b|B|br|Br|bR|BR)?"
sqstring = stringprefix + r"'[^'\\\n]*(\\.[^'\\\n]*)*'?"
dqstring = stringprefix + r'"[^"\\\n]*(\\.[^"\\\n]*)*"?'
sq3string = stringprefix + r"'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
dq3string = stringprefix + r'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
string = any("STRING", [sq3string, dq3string, sqstring, dqstring])
return kw + "|" + builtin + "|" + comment + "|" + string +\
"|" + any("SYNC", [r"\n"])
示例9: __dir__
# 需要导入模块: import keyword [as 别名]
# 或者: from keyword import kwlist [as 别名]
def __dir__(self):
allowed = string.ascii_letters + string.digits + '_'
items = set(super().__dir__())
# Only show items accessible by dot notation
for key in self.keys():
key = str(key)
if ' ' not in key and key[0] not in string.digits and key not in kwlist:
for letter in key:
if letter not in allowed:
break
else:
items.add(key)
for key in self.keys():
if key not in items:
if self._box_config['conversion_box']:
key = self._safe_attr(key)
if key:
items.add(key)
return list(items)
示例10: global_matches
# 需要导入模块: import keyword [as 别名]
# 或者: from keyword import kwlist [as 别名]
def global_matches(self, text):
"""Compute matches when text is a simple name.
Return a list of all keywords, built-in functions and names currently
defined in self.namespace that match.
"""
import keyword
matches = []
n = len(text)
for word in keyword.kwlist:
if word[:n] == text:
matches.append(word)
for nspace in [builtins.__dict__, self.namespace]:
for word, val in nspace.items():
if word[:n] == text and word != "__builtins__":
matches.append(self._callable_postfix(val, word))
return matches
示例11: unstructure_hook
# 需要导入模块: import keyword [as 别名]
# 或者: from keyword import kwlist [as 别名]
def unstructure_hook(api_model):
"""cattr unstructure hook
Map reserved_ words in models to correct json field names.
Also handle stripping None fields from dict while setting
EXPLICIT_NULL fields to None so that we only send null
in the json for fields the caller set EXPLICIT_NULL on.
"""
data = cattr.global_converter.unstructure_attrs_asdict(api_model)
for key, value in data.copy().items():
if value is None:
del data[key]
elif value == model.EXPLICIT_NULL:
data[key] = None
for reserved in keyword.kwlist:
if f"{reserved}_" in data:
data[reserved] = data.pop(f"{reserved}_")
return data
示例12: __init__
# 需要导入模块: import keyword [as 别名]
# 或者: from keyword import kwlist [as 别名]
def __init__(self, op: 'lale.operators.Operator', cls2label: Dict[str, str]):
label2count: Dict[str, int] = {}
def populate_label2count(op: 'lale.operators.Operator'):
if isinstance(op, lale.operators.IndividualOp):
label = cls2label.get(op.class_name(), op.name())
elif isinstance(op, lale.operators.BasePipeline):
for s in op.steps():
populate_label2count(s)
label = 'pipeline'
elif isinstance(op, lale.operators.OperatorChoice):
for s in op.steps():
populate_label2count(s)
label = 'choice'
label2count[label] = label2count.get(label, 0) + 1
populate_label2count(op)
non_unique_labels = {l for l, c in label2count.items() if c > 1}
snakes = {_camelCase_to_snake(l) for l in non_unique_labels}
self._names = ({'lale', 'make_pipeline', 'make_union', 'make_choice'}
| set(keyword.kwlist) | non_unique_labels | snakes)
示例13: linevars
# 需要导入模块: import keyword [as 别名]
# 或者: from keyword import kwlist [as 别名]
def linevars(code, frame=None):
if frame is None:
frame = sys._getframe().f_back
last = None
parent = None
prefix = ''
value = NOVAL
for tok_type, token, start, end, line in tokenize.generate_tokens(StringReadline(code).readline):
if tok_type == tokenize.NEWLINE:
break
elif tok_type == tokenize.NAME and token not in keyword.kwlist:
if last == '.':
if parent is not NOVAL:
value = getattr(parent, token, NOVAL)
yield prefix + token, prefix, value
else:
where, value = getvar(token, frame)
yield token, where, value
elif token == '.':
prefix = '%s%s.' % (prefix, last)
parent = value
else:
parent = None
prefix = ''
last = token