Most viewed recipes tagged "module"http://code.activestate.com/recipes/tags/module/views/2015-07-29T18:24:23-07:00ActiveState Code RecipesProgress bar class (Python)
2012-08-09T17:39:10-07:00Xavier L.http://code.activestate.com/recipes/users/4171602/http://code.activestate.com/recipes/578228-progress-bar-class/
<p style="color: grey">
Python
recipe 578228
by <a href="/recipes/users/4171602/">Xavier L.</a>
(<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/cli/">cli</a>, <a href="/recipes/tags/curses/">curses</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/module/">module</a>, <a href="/recipes/tags/progress/">progress</a>).
Revision 5.
</p>
<p>See <a href="https://gist.github.com/3306295">gist:3306295</a> for future developments.</p>
<p>Here is a little class that lets you present percent complete information in the form of a progress bar using the '=' character to represent completed portions, spaces to represent incomplete portions, '>' to represent the current portion and the actual percent done (rounded to integer) displayed at the end:</p>
<p>[===========> ] 60%</p>
<p>When you initialize the class, you specify the minimum number (defaults to 0), the maximum number (defaults to 100), and the desired width of the progress bar. The brackets <code>[]</code> are included in the size of the progress bar, but you must allow for up to 4 characters extra to display the percentage.</p>
<p>You'd probably want to use this in conjuction with the curses module, or something like that so you can over-write the same portion of the screen to make your updates 'animated'.</p>
Python script to find linux distros details from distrowatch (Python)
2015-07-29T18:24:23-07:00Emil george jameshttp://code.activestate.com/recipes/users/4191910/http://code.activestate.com/recipes/579038-python-script-to-find-linux-distros-details-from-d/
<p style="color: grey">
Python
recipe 579038
by <a href="/recipes/users/4191910/">Emil george james</a>
(<a href="/recipes/tags/beautifulsoup/">beautifulsoup</a>, <a href="/recipes/tags/internet/">internet</a>, <a href="/recipes/tags/module/">module</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/url/">url</a>, <a href="/recipes/tags/web/">web</a>).
</p>
<p>this script is a simlpe python script to find linux distros details from distrowatch using beautifulsoup,urllib2 modules.The script finds distros distribution details from <a href="http://distrowatch.com" rel="nofollow">distrowatch.com</a> when the distribution name is called as argument.</p>
Build extension modules inplace with a Makefile (Python)
2015-01-29T20:54:38-08:00Zack Weinberghttp://code.activestate.com/recipes/users/4190298/http://code.activestate.com/recipes/579016-build-extension-modules-inplace-with-a-makefile/
<p style="color: grey">
Python
recipe 579016
by <a href="/recipes/users/4190298/">Zack Weinberg</a>
(<a href="/recipes/tags/compiler/">compiler</a>, <a href="/recipes/tags/module/">module</a>).
</p>
<p>Do you find distutils to be poorly documented, overdesigned yet still inadequate, and far too difficult to do anything out of the ordinary with? Do you find yourself wishing that you could just write a Makefile for your extension modules, if only you knew how to form the compile commands?</p>
<p>Then this tool is for you. An example (GNU) makefile to use it with is embedded in the code; it assumes you save this program as <code>get-module-compile-cmds.py</code> in the same directory as the makefile. Tested with 2.7 and 3.4; may work with older versions as well.</p>
<p>Installation is not currently supported; patches welcome.</p>
Markov Encryption Module (Python)
2012-09-05T20:25:49-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578075-markov-encryption-module/
<p style="color: grey">
Python
recipe 578075
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/library/">library</a>, <a href="/recipes/tags/module/">module</a>, <a href="/recipes/tags/utility/">utility</a>).
Revision 7.
</p>
<p>This module exposes primitives useful for executing Markov Encryption
processes. ME was inspired by a combination of Markov chains with the
puzzles of Sudoku. This implementation has undergone numerous changes
and optimizations since its original design. Please see documentation.</p>
Using doctests to verify a module's export list (Python)
2012-09-19T19:13:20-07:00Sam Dentonhttp://code.activestate.com/recipes/users/4172262/http://code.activestate.com/recipes/578266-using-doctests-to-verify-a-modules-export-list/
<p style="color: grey">
Python
recipe 578266
by <a href="/recipes/users/4172262/">Sam Denton</a>
(<a href="/recipes/tags/doctest/">doctest</a>, <a href="/recipes/tags/export/">export</a>, <a href="/recipes/tags/module/">module</a>, <a href="/recipes/tags/python/">python</a>).
Revision 2.
</p>
<p>If you aren't very careful, modules can end up exporting more symbols than you intend. For example, everything that you import is added to your module's name-space. Then there's scaffolding and other stuff intended for internal use. The usual advice is to name everything with a leading underscore, but that gets complicated fast: "import sys as _sys", "from os import environ as _environ". The alternative is to use "__all__ " to define exactly what you want to export, but then you need to maintain it as you add things to your module. <em>Or do you?</em></p>
(Ab)Using Modules as Namespaces (Python)
2012-05-10T04:14:06-07:00Wolfgang Schererhttp://code.activestate.com/recipes/users/4182020/http://code.activestate.com/recipes/578122-abusing-modules-as-namespaces/
<p style="color: grey">
Python
recipe 578122
by <a href="/recipes/users/4182020/">Wolfgang Scherer</a>
(<a href="/recipes/tags/module/">module</a>, <a href="/recipes/tags/namespaces/">namespaces</a>, <a href="/recipes/tags/vars/">vars</a>).
</p>
<p>I have previously built a shar-like Python utility, which reads (marked) imported modules, gzips and base64 encodes them, then generates a python script, which is fully standalone.</p>
<p>The included module source is placed into sys.modules at runtime, making imports possible without actually having the module files installed. A very nice thing for administrative scripts that have to work in unconfigured environments.</p>
<p>At that time I discovered a lot of information about how modules in Python work.</p>
<p>Reading the very interesting recipe at <a href="http://code.activestate.com/recipes/577887-a-simple-namespace-class/" rel="nofollow">http://code.activestate.com/recipes/577887-a-simple-namespace-class/</a>
made me realize, that modules are actually very useful as generic namespaces too.</p>
Markov Encryption Module (for Python 2.5) (Python)
2012-07-25T22:33:03-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578135-markov-encryption-module-for-python-25/
<p style="color: grey">
Python
recipe 578135
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/library/">library</a>, <a href="/recipes/tags/module/">module</a>, <a href="/recipes/tags/utility/">utility</a>).
Revision 4.
</p>
<p>This module provides classes that are useful for executing Markov encryption and decryption on data. ME was inspired by a combination of Markov chains with the puzzles of Sudoku. This implementation is a rewrite from the Python 3.x version and includes various changes and optimizations to work with Python 2.5 and related versions. All documentation has been left in <a href="http://code.activestate.com/recipes/578075/">recipe 578075</a> and should be referred to there.</p>