Popular recipes by Glenn http://code.activestate.com/recipes/users/4171639/2012-05-12T06:21:11-07:00ActiveState Code RecipesMultidimensional list (Python) 2012-05-12T06:21:11-07:00Glennhttp://code.activestate.com/recipes/users/4171639/http://code.activestate.com/recipes/578127-multidimensional-list/ <p style="color: grey"> Python recipe 578127 by <a href="/recipes/users/4171639/">Glenn</a> . Revision 2. </p> <p>Pass a tuple of positive integers of length N (any length) as dimensions to MDarray, and a list is created with the length equal to the product NNN of the dimensions specified in the tuple. The items are initialized to None, or to the value of the optional init parameter. As a special case, passing an integer for dims creates a square array of that size (converts the integer to a tuple of length two with the same value for both entries).</p> <p>You can then index the list with single numbers in range(NNN), or by a tuple of the same length N with which the list was created.</p> <pre class="prettyprint"><code>ary = MDarray(( 5, 6, 8 ), 0 ) ix = ary.index_from_tuple(( 2, 4, 3 )) print( ix ) # 87 print( ary[ 2, 4, 2 ], ary[ 2, 4, 3 ], ary[ 2, 4, 4 ]) # 0, 0, 0 print( ary[ 86 ], ary[ 87 ], ary[ 88 ]) # 0, 0, 0 ary[ 2, 4, 3 ] = 25 print( ary[ 2, 4, 2 ], ary[ 2, 4, 3 ], ary[ 2, 4, 4 ]) # 0, 25, 0 print( ary[ 86 ], ary[ 87 ], ary[ 88 ]) # 0, 25, 0 </code></pre> ZipScript: Build a directly executable zipped Python script set (Python) 2010-02-11T15:32:38-08:00Glennhttp://code.activestate.com/recipes/users/4171639/http://code.activestate.com/recipes/577042-zipscript-build-a-directly-executable-zipped-pytho/ <p style="color: grey"> Python recipe 577042 by <a href="/recipes/users/4171639/">Glenn</a> (<a href="/recipes/tags/package/">package</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/zip/">zip</a>). Revision 2. </p> <p>This function will package a python script and additional python modules, in either source or compiled form. Either are directly executable by Python 2.7/3.1 or newer.</p> <p>Uses make-like logic to only rebuild if something is newer than the previous build.</p>