本文整理匯總了Python中six.moves.map方法的典型用法代碼示例。如果您正苦於以下問題:Python moves.map方法的具體用法?Python moves.map怎麽用?Python moves.map使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類six.moves
的用法示例。
在下文中一共展示了moves.map方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: multi_apply
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def multi_apply(func, *args, **kwargs):
"""Apply function to a list of arguments.
Note:
This function applies the ``func`` to multiple inputs and
map the multiple outputs of the ``func`` into different
list. Each list contains the same type of outputs corresponding
to different inputs.
Args:
func (Function): A function that will be applied to a list of
arguments
Returns:
tuple(list): A tuple containing multiple list, each list contains
a kind of returned results by the function
"""
pfunc = partial(func, **kwargs) if kwargs else func
map_results = map(pfunc, *args)
return tuple(map(list, zip(*map_results)))
示例2: __init__
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def __init__(self, search_path=None, platform=get_supported_platform(),
python=PY_MAJOR):
"""Snapshot distributions available on a search path
Any distributions found on `search_path` are added to the environment.
`search_path` should be a sequence of ``sys.path`` items. If not
supplied, ``sys.path`` is used.
`platform` is an optional string specifying the name of the platform
that platform-specific distributions must be compatible with. If
unspecified, it defaults to the current platform. `python` is an
optional string naming the desired version of Python (e.g. ``'3.3'``);
it defaults to the current version.
You may explicitly set `platform` (and/or `python`) to ``None`` if you
wish to map *all* distributions, not just those compatible with the
running platform or Python version.
"""
self._distmap = {}
self.platform = platform
self.python = python
self.scan(search_path)
示例3: parse_map
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def parse_map(cls, data, dist=None):
"""Parse a map of entry point groups"""
if isinstance(data, dict):
data = data.items()
else:
data = split_sections(data)
maps = {}
for group, lines in data:
if group is None:
if not lines:
continue
raise ValueError("Entry points must be listed in groups")
group = group.strip()
if group in maps:
raise ValueError("Duplicate group name", group)
maps[group] = cls.parse_group(group, lines, dist)
return maps
示例4: __init__
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def __init__(
self, search_path=None, platform=get_supported_platform(),
python=PY_MAJOR):
"""Snapshot distributions available on a search path
Any distributions found on `search_path` are added to the environment.
`search_path` should be a sequence of ``sys.path`` items. If not
supplied, ``sys.path`` is used.
`platform` is an optional string specifying the name of the platform
that platform-specific distributions must be compatible with. If
unspecified, it defaults to the current platform. `python` is an
optional string naming the desired version of Python (e.g. ``'3.3'``);
it defaults to the current version.
You may explicitly set `platform` (and/or `python`) to ``None`` if you
wish to map *all* distributions, not just those compatible with the
running platform or Python version.
"""
self._distmap = {}
self.platform = platform
self.python = python
self.scan(search_path)
示例5: query_shards
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def query_shards(self, query):
"""
Return the result of applying shard[query] for each shard in self.shards,
as a sequence.
If PARALLEL_SHARDS is set, the shards are queried in parallel, using
the multiprocessing module.
"""
args = zip([query] * len(self.shards), self.shards)
if PARALLEL_SHARDS and PARALLEL_SHARDS > 1:
logger.debug("spawning %i query processes" % PARALLEL_SHARDS)
pool = multiprocessing.Pool(PARALLEL_SHARDS)
result = pool.imap(query_shard, args, chunksize=1 + len(args) / PARALLEL_SHARDS)
else:
# serial processing, one shard after another
pool = None
result = imap(query_shard, args)
return pool, result
示例6: _from_word2vec_binary
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def _from_word2vec_binary(fname):
with _open(fname, 'rb') as fin:
words = []
header = _decode(fin.readline())
vocab_size, layer1_size = list(map(int, header.split())) # throws for invalid file format
vectors = np.zeros((vocab_size, layer1_size), dtype=float32)
binary_len = np.dtype(float32).itemsize * layer1_size
for line_no in xrange(vocab_size):
# mixed text and binary: read text first, then binary
word = []
while True:
ch = fin.read(1)
if ch == b' ':
break
if ch != b'\n': # ignore newlines in front of words (some binary files have newline, some don't)
word.append(ch)
word = _decode(b''.join(word))
index = line_no
words.append(word)
vectors[index, :] = np.fromstring(fin.read(binary_len), dtype=float32)
return words, vectors
示例7: mapall
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def mapall(funcs, seq):
"""
Parameters
----------
funcs : iterable[function]
Sequence of functions to map over `seq`.
seq : iterable
Sequence over which to map funcs.
Yields
------
elem : object
Concatenated result of mapping each ``func`` over ``seq``.
Example
-------
>>> list(mapall([lambda x: x + 1, lambda x: x - 1], [1, 2, 3]))
[2, 3, 4, 0, 1, 2]
"""
for func in funcs:
for elem in seq:
yield func(elem)
示例8: _setattr
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def _setattr(self, name, value):
# if this attribute has special type assigned to it...
if name in self._param_defs:
pinfo = self._param_defs[name]
if 'type' in pinfo:
# get the shortcut used to construct this type (query.Q, aggs.A, etc)
shortcut = self.__class__.get_dsl_type(pinfo['type'])
if pinfo.get('multi'):
value = list(map(shortcut, value))
# dict(name -> DslBase), make sure we pickup all the objs
elif pinfo.get('hash'):
value = dict((k, shortcut(v)) for (k, v) in iteritems(value))
# single value object, just convert
else:
value = shortcut(value)
self._params[name] = value
示例9: _compile_literal
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def _compile_literal(self, element, src_state, dst_state, grammar, kaldi_rule, fst):
weight = self.get_weight(element) # Handle weight internally below, without adding a state
words = element.words
words = list(map(text_type, words))
# words = self.translate_words(words)
# Special case optimize single-word literal
if len(words) == 1:
word = words[0].lower()
if word not in self.lexicon_words:
word = self.handle_oov_word(word)
fst.add_arc(src_state, dst_state, word, weight=weight)
else:
words = [word.lower() for word in words]
for i in range(len(words)):
if words[i] not in self.lexicon_words:
words[i] = self.handle_oov_word(words[i])
# "Insert" new states for individual words
states = [src_state] + [fst.add_state() for i in range(len(words)-1)] + [dst_state]
for i, word in enumerate(words):
fst.add_arc(states[i], states[i + 1], word, weight=weight)
weight = None # Only need to set weight on first arc
# @trace_compile
示例10: find_external_links
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def find_external_links(url, page):
"""Find rel="homepage" and rel="download" links in `page`, yielding URLs"""
for match in REL.finditer(page):
tag, rel = match.groups()
rels = set(map(str.strip, rel.lower().split(',')))
if 'homepage' in rels or 'download' in rels:
for match in HREF.finditer(tag):
yield urllib.parse.urljoin(url, htmldecode(match.group(1)))
for tag in ("<th>Home Page", "<th>Download URL"):
pos = page.find(tag)
if pos != -1:
match = HREF.search(page, pos)
if match:
yield urllib.parse.urljoin(url, htmldecode(match.group(1)))
示例11: __init__
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def __init__(
self, index_url="https://pypi.python.org/simple", hosts=('*',),
ca_bundle=None, verify_ssl=True, *args, **kw
):
Environment.__init__(self, *args, **kw)
self.index_url = index_url + "/" [:not index_url.endswith('/')]
self.scanned_urls = {}
self.fetched_urls = {}
self.package_pages = {}
self.allows = re.compile('|'.join(map(translate, hosts))).match
self.to_scan = []
use_ssl = (
verify_ssl
and ssl_support.is_available
and (ca_bundle or ssl_support.find_ca_bundle())
)
if use_ssl:
self.opener = ssl_support.opener_for(ca_bundle)
else:
self.opener = urllib.request.urlopen
示例12: install_namespaces
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def install_namespaces(self):
nsp = self._get_all_ns_packages()
if not nsp:
return
filename, ext = os.path.splitext(self._get_target())
filename += self.nspkg_ext
self.outputs.append(filename)
log.info("Installing %s", filename)
lines = map(self._gen_nspkg_line, nsp)
if self.dry_run:
# always generate the lines, even in dry run
list(lines)
return
with open(filename, 'wt') as f:
f.writelines(lines)
示例13: multi_apply
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def multi_apply(func, *args, **kwargs):
pfunc = partial(func, **kwargs) if kwargs else func
map_results = map(pfunc, *args)
return tuple(map(list, zip(*map_results)))
示例14: velocity
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def velocity(momentum, mass):
return map(lambda z: z[0] / z[1], zip(momentum, mass))
示例15: test_parser_test_completeness
# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import map [as 別名]
def test_parser_test_completeness(self):
"""ensure that all rules in grammar have tests"""
grammar_rule_re = re.compile(r"^(\w+)")
grammar_fn = pkg_resources.resource_filename("hgvs", "_data/hgvs.pymeta")
with open(grammar_fn, "r") as f:
grammar_rules = set(r.group(1) for r in filter(None, map(grammar_rule_re.match, f)))
with open(self._test_fn, "r") as f:
reader = csv.DictReader(f, delimiter=str("\t"))
test_rules = set(row["Func"] for row in reader)
untested_rules = grammar_rules - test_rules
self.assertTrue(len(untested_rules) == 0, "untested rules: {}".format(untested_rules))