snipt

Ctrl+h for KB shortcuts

Python

create an alias/partial in python

1
2
3
# create a partial that can be applied using map with the give size
checkThisSize = functools.partial(checkSize, size=options.size, quiet=False)
checked = map(checkThisSize, queues)
https://snipt.net/embed/d87ad598037174ab3e56867222140fae/
/raw/d87ad598037174ab3e56867222140fae/
d87ad598037174ab3e56867222140fae
python
Python
4
2019-07-11T10:45:06
True
False
False
/api/public/snipt/985/
create-an-aliaspartial-in-python
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># create a partial that can be applied using map with the give size</span> </span><span id="L-2"><a name="L-2"></a><span class="n">checkThisSize</span> <span class="o">=</span> <span class="n">functools</span><span class="o">.</span><span class="n">partial</span><span class="p">(</span><span class="n">checkSize</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">size</span><span class="p">,</span> <span class="n">quiet</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a><span class="n">checked</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="n">checkThisSize</span><span class="p">,</span> <span class="n">queues</span><span class="p">)</span> </span></pre></div> </td></tr></table>
functional, partial, python