Top-rated recipes tagged "python" and "python3" but not "statistics"http://code.activestate.com/recipes/tags/python+python3-statistics/top/2017-01-05T16:57:15-08:00ActiveState Code RecipesGive Python code a web plus command-line interface with hug (Python)
2017-01-05T16:57:15-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580742-give-python-code-a-web-plus-command-line-interface/
<p style="color: grey">
Python
recipe 580742
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/cli/">cli</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/hug/">hug</a>, <a href="/recipes/tags/library/">library</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/user_interface/">user_interface</a>, <a href="/recipes/tags/web/">web</a>, <a href="/recipes/tags/web_server/">web_server</a>).
</p>
<p>This recipe shows how to take a Python function and wrap it with both a web and a command-line interface, somewhat easily, using the hug Python library. The example used shows how to wrap a function that uses the psutil library to get information on disk partitions. So you can see the disk partition info either via the web browser or the command line. The code for the recipe is shown below. It is also possible to wrap multiple functions in the same Python file, and expose all of them via both the web and the command-line.</p>
<p>More information and multiple sample outputs are available here:</p>
<p><a href="https://jugad2.blogspot.in/2017/01/give-your-python-function-webcli-hug.html" rel="nofollow">https://jugad2.blogspot.in/2017/01/give-your-python-function-webcli-hug.html</a></p>
Handle exit context manager (Python)
2014-08-01T08:28:07-07:00Giampaolo Rodolàhttp://code.activestate.com/recipes/users/4178764/http://code.activestate.com/recipes/577997-handle-exit-context-manager/
<p style="color: grey">
Python
recipe 577997
by <a href="/recipes/users/4178764/">Giampaolo Rodolà</a>
(<a href="/recipes/tags/atexit/">atexit</a>, <a href="/recipes/tags/contextlib/">contextlib</a>, <a href="/recipes/tags/contextmanager/">contextmanager</a>, <a href="/recipes/tags/exit/">exit</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/shutdown/">shutdown</a>, <a href="/recipes/tags/sigint/">sigint</a>, <a href="/recipes/tags/signal/">signal</a>, <a href="/recipes/tags/sigterm/">sigterm</a>).
Revision 23.
</p>
<p>A context manager which properly handles SIGTERM (SystemExit) and SIGINT (KeyboardInterrupt) signals, registering a function which is always guaranteed to be called on interpreter exit.
Also, it makes sure to execute previously registered functions as well (if any).</p>
LRU dictionary (Python)
2016-04-17T01:22:51-07:00Felixhttp://code.activestate.com/recipes/users/4193957/http://code.activestate.com/recipes/580645-lru-dictionary/
<p style="color: grey">
Python
recipe 580645
by <a href="/recipes/users/4193957/">Felix</a>
(<a href="/recipes/tags/dict/">dict</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/expires/">expires</a>, <a href="/recipes/tags/expiring/">expiring</a>, <a href="/recipes/tags/lru/">lru</a>, <a href="/recipes/tags/lru_cache/">lru_cache</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3/">python3</a>).
</p>
<p>For most cases where you want to store a limited amount of data, functools.partial is sufficient. However, if you want or need more control over your data, especially specifying an expiration date for your entries, this can come in handy.</p>
<p>Read the docstrings for implementation details.</p>
PyOOCalc - Python Libre/Open Office Calc Interface API (UNO) (Python)
2016-01-10T13:12:53-08:00Yuriihttp://code.activestate.com/recipes/users/4193384/http://code.activestate.com/recipes/579147-pyoocalc-python-libreopen-office-calc-interface-ap/
<p style="color: grey">
Python
recipe 579147
by <a href="/recipes/users/4193384/">Yurii</a>
(<a href="/recipes/tags/openoffice/">openoffice</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3/">python3</a>).
</p>
<p>Create Libre/Open Office Calc documents, reports on Python</p>
@unittest.skip_others decorator (Python)
2012-08-06T02:20:19-07:00Giampaolo Rodolàhttp://code.activestate.com/recipes/users/4178764/http://code.activestate.com/recipes/578234-unittestskip_others-decorator/
<p style="color: grey">
Python
recipe 578234
by <a href="/recipes/users/4178764/">Giampaolo Rodolà</a>
(<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/skip/">skip</a>, <a href="/recipes/tags/unittest/">unittest</a>).
Revision 3.
</p>
<p>Decorator which skips all tests except the one decorated with it.
Based on original proposal on python-ideas:
<a href="http://mail.python.org/pipermail/python-ideas/2010-August/007992.html" rel="nofollow">http://mail.python.org/pipermail/python-ideas/2010-August/007992.html</a></p>
(gopytranslte) script google translator (Python)
2011-04-14T17:17:12-07:00namakukingkonghttp://code.activestate.com/recipes/users/4176734/http://code.activestate.com/recipes/577556-gopytranslte-script-google-translator/
<p style="color: grey">
Python
recipe 577556
by <a href="/recipes/users/4176734/">namakukingkong</a>
(<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/google/">google</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/translate/">translate</a>, <a href="/recipes/tags/translator/">translator</a>).
Revision 3.
</p>
<p>hehehehe..... Very little code for study.....</p>
Hashing Nonhashable / Mutable Objects (Python)
2015-04-16T12:11:34-07:00Max Morozhttp://code.activestate.com/recipes/users/4168744/http://code.activestate.com/recipes/579047-hashing-nonhashable-mutable-objects/
<p style="color: grey">
Python
recipe 579047
by <a href="/recipes/users/4168744/">Max Moroz</a>
(<a href="/recipes/tags/hash/">hash</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3/">python3</a>).
Revision 2.
</p>
<p>This class is intended as a wrapper for non-hashable objects (such as lists, dictionaries, etc.) in situations where the object is known to be immutable. Example: memoization of function arguments.</p>
<p>Feedback much appreciated, I will update to reflect any comments.</p>