本文整理匯總了Python中__builtin__.enumerate方法的典型用法代碼示例。如果您正苦於以下問題:Python __builtin__.enumerate方法的具體用法?Python __builtin__.enumerate怎麽用?Python __builtin__.enumerate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類__builtin__
的用法示例。
在下文中一共展示了__builtin__.enumerate方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_callable_argspec_py2
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import enumerate [as 別名]
def _get_callable_argspec_py2(func):
argspec = inspect.getargspec(func)
varpos = argspec.varargs
varkw = argspec.keywords
args = argspec.args
tuplearg = False
for elem in args:
tuplearg = tuplearg or isinstance(elem, list)
if tuplearg:
msg = 'tuple argument(s) found'
raise FyppFatalError(msg)
defaults = {}
if argspec.defaults is not None:
for ind, default in enumerate(argspec.defaults):
iarg = len(args) - len(argspec.defaults) + ind
defaults[args[iarg]] = default
return args, defaults, varpos, varkw
示例2: enumerate
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import enumerate [as 別名]
def enumerate(thing, start=0):
result = []
for i, item in bltin_enumerate(thing):
i = i + start
result.append((i, item))
return result
示例3: __new__
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import enumerate [as 別名]
def __new__(cls, iterable, start=0):
new_enumerate = _coconut.enumerate.__new__(cls, iterable, start)
new_enumerate.iter = iterable
new_enumerate.start = start
return new_enumerate
示例4: __repr__
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import enumerate [as 別名]
def __repr__(self):
return "enumerate(%r, %r)" % (self.iter, self.start)
示例5: __call__
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import enumerate [as 別名]
def __call__(self, *args, **kwargs):
key = (args, _coconut.frozenset(kwargs))
use_backup = False
try:
hash(key)
except _coconut.Exception:
try:
key = _coconut.pickle.dumps(key, -1)
except _coconut.Exception:
use_backup = True
if use_backup:
for i, (k, v) in _coconut.enumerate(self.backup_tee_store):
if k == key:
to_tee, store_pos = v, i
break
else: # no break
to_tee = self.func(*args, **kwargs)
store_pos = None
to_store, to_return = _coconut_tee(to_tee)
if store_pos is None:
self.backup_tee_store.append([key, to_store])
else:
self.backup_tee_store[store_pos][1] = to_store
else:
self.tee_store[key], to_return = _coconut_tee(self.tee_store.get(key) or self.func(*args, **kwargs))
return to_return
示例6: _get_call_arguments
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import enumerate [as 別名]
def _get_call_arguments(self, fname, spans, argexpr, contents, argnames):
if argexpr is None:
posargs = []
kwargs = {}
else:
# Parse and evaluate arguments passed in call header
self._evaluator.openscope()
try:
posargs, kwargs = self._evaluate(
'__getargvalues(' + argexpr + ')', fname, spans[0][0])
except Exception as exc:
msg = "unable to parse argument expression '{0}'"\
.format(argexpr)
raise FyppFatalError(msg, fname, spans[0], exc)
self._evaluator.closescope()
# Render arguments passed in call body
args = []
for content in contents:
self._evaluator.openscope()
rendered = self.render(content, divert=True)
self._evaluator.closescope()
if rendered.endswith('\n'):
rendered = rendered[:-1]
args.append(rendered)
# Separate arguments in call body into positional and keyword ones:
if argnames:
posargs += args[:len(args) - len(argnames)]
offset = len(args) - len(argnames)
for iargname, argname in enumerate(argnames):
ind = offset + iargname
if argname in kwargs:
msg = "keyword argument '{0}' already defined"\
.format(argname)
raise FyppFatalError(msg, fname, spans[ind + 1])
kwargs[argname] = args[ind]
else:
posargs += args
return posargs, kwargs
示例7: _postprocess_eval_lines
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import enumerate [as 別名]
def _postprocess_eval_lines(self, output, eval_inds, eval_pos):
ilastproc = -1
for ieval, ind in enumerate(eval_inds):
span, fname = eval_pos[ieval]
if ind <= ilastproc:
continue
iprev, eolprev = self._find_last_eol(output, ind)
inext, eolnext = self._find_next_eol(output, ind)
curline = self._glue_line(output, ind, iprev, eolprev, inext,
eolnext)
output[iprev + 1:inext] = [''] * (inext - iprev - 1)
output[ind] = self._postprocess_eval_line(curline, fname, span)
ilastproc = inext
示例8: _argsplit_fortran
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import enumerate [as 別名]
def _argsplit_fortran(argtxt):
txt = _INLINE_EVAL_REGION_REGEXP.sub(_blank_match, argtxt)
splitpos = [-1]
quote = None
closing_brace_stack = []
closing_brace = None
for ind, char in enumerate(txt):
if quote:
if char == quote:
quote = None
continue
if char in _QUOTES_FORTRAN:
quote = char
continue
if char in _OPENING_BRACKETS_FORTRAN:
closing_brace_stack.append(closing_brace)
ind = _OPENING_BRACKETS_FORTRAN.index(char)
closing_brace = _CLOSING_BRACKETS_FORTRAN[ind]
continue
if char in _CLOSING_BRACKETS_FORTRAN:
if char == closing_brace:
closing_brace = closing_brace_stack.pop(-1)
continue
else:
msg = "unexpected closing delimiter '{0}' in expression '{1}' "\
"at position {2}".format(char, argtxt, ind + 1)
raise FyppFatalError(msg)
if not closing_brace and char == _ARGUMENT_SPLIT_CHAR_FORTRAN:
splitpos.append(ind)
if quote or closing_brace:
msg = "open quotes or brackets in expression '{0}'".format(argtxt)
raise FyppFatalError(msg)
splitpos.append(len(txt))
fragments = [argtxt[start + 1 : end]
for start, end in zip(splitpos, splitpos[1:])]
return fragments