Popular recipes tagged "meta:loc=23"http://code.activestate.com/recipes/tags/meta:loc=23/2016-05-29T10:50:33-07:00ActiveState Code RecipesTiming a batch program (Batch) 2016-05-29T10:50:33-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/580670-timing-a-batch-program/ <p style="color: grey"> Batch recipe 580670 by <a href="/recipes/users/4182514/">Antoni Gual</a> (<a href="/recipes/tags/batch/">batch</a>, <a href="/recipes/tags/timing/">timing</a>). </p> <p>It uses %time% to time a function to the hundredth of second.</p> How a Python function can find the name of its caller (Python) 2015-09-30T15:12:17-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579105-how-a-python-function-can-find-the-name-of-its-cal/ <p style="color: grey"> Python recipe 579105 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/evaluation/">evaluation</a>, <a href="/recipes/tags/introspection/">introspection</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sys/">sys</a>). </p> <p>This recipe shows how a Python function can find out the name of its caller, i.e. which other Python function has called it.</p> Printing list of ODBC data sources with pyodbc module (Python) 2014-01-28T10:40:56-08:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/578815-printing-list-of-odbc-data-sources-with-pyodbc-mod/ <p style="color: grey"> Python recipe 578815 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/odbc/">odbc</a>, <a href="/recipes/tags/sql/">sql</a>). </p> <p>I have similar recipe but with <code>odbc</code> module: <a href="http://code.activestate.com/recipes/578782-printing-list-of-odbc-data-sources/" rel="nofollow">http://code.activestate.com/recipes/578782-printing-list-of-odbc-data-sources/</a></p> Using QMacCocoaViewContainer on PyQt4 (Python) 2014-10-17T10:40:48-07:00Keisuke URAGOhttp://code.activestate.com/recipes/users/668964/http://code.activestate.com/recipes/578951-using-qmaccocoaviewcontainer-on-pyqt4/ <p style="color: grey"> Python recipe 578951 by <a href="/recipes/users/668964/">Keisuke URAGO</a> (<a href="/recipes/tags/pyqt/">pyqt</a>). </p> <p>This code is QMacCocoaViewContainer on PyQt4 example.</p> Get a value un windows registry (Python) 2013-10-15T07:30:39-07:00Garel Alexhttp://code.activestate.com/recipes/users/2757636/http://code.activestate.com/recipes/578689-get-a-value-un-windows-registry/ <p style="color: grey"> Python recipe 578689 by <a href="/recipes/users/2757636/">Garel Alex</a> (<a href="/recipes/tags/registry/">registry</a>, <a href="/recipes/tags/win32api/">win32api</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>A small function to get a value in windows registry from its key path and value name.</p> <p>Note that recipe <a href="http://code.activestate.com/recipes/502268/" rel="nofollow">http://code.activestate.com/recipes/502268/</a> gives a more complete solution.</p> Priority Queue (with deletion) (Python) 2013-12-08T21:12:55-08:00elazarhttp://code.activestate.com/recipes/users/4187847/http://code.activestate.com/recipes/578780-priority-queue-with-deletion/ <p style="color: grey"> Python recipe 578780 by <a href="/recipes/users/4187847/">elazar</a> (<a href="/recipes/tags/artificial_intelligence/">artificial_intelligence</a>, <a href="/recipes/tags/heap/">heap</a>, <a href="/recipes/tags/heapq/">heapq</a>, <a href="/recipes/tags/priority_queue/">priority_queue</a>, <a href="/recipes/tags/queue/">queue</a>). Revision 5. </p> <p>Based on the interface defined in aima-python <a href="http://aima-python.googlecode.com/svn/trunk/utils.py" rel="nofollow">http://aima-python.googlecode.com/svn/trunk/utils.py</a></p> <p>Yields better performance.</p> Unix head -n analog (Batch) 2013-10-12T17:40:06-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578688-unix-head-n-analog/ <p style="color: grey"> Batch recipe 578688 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/head/">head</a>). </p> <p>Reads first N strings in text file. It looks like <a href="http://code.activestate.com/recipes/578311-unix-tail-n-analog/">tail -n</a></p> Calculating PI using trigonometric iterations (Python) 2013-08-25T06:24:56-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578651-calculating-pi-using-trigonometric-iterations/ <p style="color: grey"> Python recipe 578651 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/pi/">pi</a>). </p> <p>Calculating PI using trigonometric iterations</p> de Polignac's Formula (Python) 2013-08-10T03:40:02-07:00Samuel James Ericksonhttp://code.activestate.com/recipes/users/4187478/http://code.activestate.com/recipes/578632-de-polignacs-formula/ <p style="color: grey"> Python recipe 578632 by <a href="/recipes/users/4187478/">Samuel James Erickson</a> (<a href="/recipes/tags/factorial/">factorial</a>, <a href="/recipes/tags/n/">n</a>, <a href="/recipes/tags/prime/">prime</a>, <a href="/recipes/tags/primes/">primes</a>). Revision 4. </p> <p>Obtains the total number of factors of p in n! for any prime p.</p> Extending non-extendable C++ based Python classes (Python) 2013-07-18T10:02:59-07:00Ahmet Emre Aladağhttp://code.activestate.com/recipes/users/4174877/http://code.activestate.com/recipes/578576-extending-non-extendable-c-based-python-classes/ <p style="color: grey"> Python recipe 578576 by <a href="/recipes/users/4174877/">Ahmet Emre Aladağ</a> (<a href="/recipes/tags/attribute/">attribute</a>, <a href="/recipes/tags/proxy/">proxy</a>, <a href="/recipes/tags/subclass/">subclass</a>). Revision 2. </p> <p>graph_tool library is based on boost C++ library and provides Vertex class binding for Python. If we wanted to extend this Vertex class and add some attributes and methods, it wouldn't let us do that due to private constructor in C++ code (RuntimeError: This class cannot be instantiated from Python). We can overcome this obstacle using Proxy pattern.</p> <p>In the __getattr__ method, if the attribute(or function name) is not in the Subclass MyVertex, then it looks for attributes of Vertex object that is defined inside MyVertex.</p> Split a sequence or generator using a predicate (Python) 2013-01-21T16:20:17-08:00Paul McGuirehttp://code.activestate.com/recipes/users/1377254/http://code.activestate.com/recipes/578416-split-a-sequence-or-generator-using-a-predicate/ <p style="color: grey"> Python recipe 578416 by <a href="/recipes/users/1377254/">Paul McGuire</a> (<a href="/recipes/tags/partition/">partition</a>, <a href="/recipes/tags/sequence/">sequence</a>, <a href="/recipes/tags/splitting/">splitting</a>). Revision 3. </p> <p>Split a sequence or generator into two iterators, each iterating over the elements that either pass or fail a predicate function.</p> Ten's Multiplication Algorithms in Python (Python) 2013-06-18T15:23:36-07:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578566-tens-multiplication-algorithms-in-python/ <p style="color: grey"> Python recipe 578566 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/multiplication/">multiplication</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>Here is a very simple program in Python to multiply 2 numbers. This is following a Ten's multiplication algorithms. I worte for my blog <a href="http://thelivingpearl.com/basic-multiplication-in-python/">Captain DeadBones Chronicles</a></p> Komodo JS Macro - show git blame for the current editor line (JavaScript) 2013-05-28T18:59:52-07:00Philip Cooperhttp://code.activestate.com/recipes/users/4168074/http://code.activestate.com/recipes/578537-komodo-js-macro-show-git-blame-for-the-current-edi/ <p style="color: grey"> JavaScript recipe 578537 by <a href="/recipes/users/4168074/">Philip Cooper</a> (<a href="/recipes/tags/blame/">blame</a>, <a href="/recipes/tags/git/">git</a>, <a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/scc/">scc</a>). </p> <p>A <a href="http://www.activestate.com/komodo">Komodo</a> JavaScript macro that can show the SCC repository information for who last changed the current line in the Komodo editor - see the screenshot below.</p> <p><img src="http://community.activestate.com/files/images/svn_blame.png" alt="svn blame image" /></p> Secant Method of Solving Equtions in Python (Python) 2013-01-16T16:42:26-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578420-secant-method-of-solving-equtions-in-python/ <p style="color: grey"> Python recipe 578420 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/pytho/">pytho</a>, <a href="/recipes/tags/secant/">secant</a>). </p> <p>Solving equations using the Newton's method without taking derivatives. This code war written for the article <a href="http://thelivingpearl.com/2013/01/15/the-easy-way-to-solve-equations-in-python/">How to solve equations using python</a>.</p> File To Hex (Python) 2012-12-05T23:45:05-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578360-file-to-hex/ <p style="color: grey"> Python recipe 578360 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/demonstration/">demonstration</a>). </p> <p>There are lots of hex editors out there, but how difficult is it to actually write a program that just displays a file in simple hex format? As this recipe shows, a few functions and lines in Python makes it rather easy to accomplish.</p> Local Secure (Perl) 2012-09-30T19:32:11-07:00Roger Mbiama Assogohttp://code.activestate.com/recipes/users/4182949/http://code.activestate.com/recipes/578274-local-secure/ <p style="color: grey"> Perl recipe 578274 by <a href="/recipes/users/4182949/">Roger Mbiama Assogo</a> (<a href="/recipes/tags/any/">any</a>, <a href="/recipes/tags/os_walk/">os_walk</a>). </p> <p>Debian LINUX os</p> Tracking Child Classes (Python) 2012-05-30T10:00:21-07:00Evert van de Waalhttp://code.activestate.com/recipes/users/4182118/http://code.activestate.com/recipes/578137-tracking-child-classes/ <p style="color: grey"> Python recipe 578137 by <a href="/recipes/users/4182118/">Evert van de Waal</a> (<a href="/recipes/tags/child/">child</a>, <a href="/recipes/tags/classes/">classes</a>). </p> <p>This recipe allows a base class to keep track of the child classes that inherit from it using a metaclass.</p> Convert a nested Python data structure to XML (Python) 2011-10-17T12:48:59-07:00Graham Poulterhttp://code.activestate.com/recipes/users/4172291/http://code.activestate.com/recipes/577882-convert-a-nested-python-data-structure-to-xml/ <p style="color: grey"> Python recipe 577882 by <a href="/recipes/users/4172291/">Graham Poulter</a> (<a href="/recipes/tags/serialize/">serialize</a>, <a href="/recipes/tags/xml/">xml</a>). Revision 2. </p> <p>Uses lxml.etree to convert a Python object consisting of nested dicts, tuples, lists, strings and string-convertable objects into a very basic no-attributes, untyped dialect of XML in which elements are named after dictionary keys, and "&lt;i&gt;" is the element for anonymous list and tuple items.</p> <p>Does not support: encoding or decoding of strings, invalid floating point values, detection of circular references.</p> Equally-spaced floats part 2 (Python) 2011-09-27T15:48:00-07:00Steven D'Apranohttp://code.activestate.com/recipes/users/4172944/http://code.activestate.com/recipes/577881-equally-spaced-floats-part-2/ <p style="color: grey"> Python recipe 577881 by <a href="/recipes/users/4172944/">Steven D'Aprano</a> (<a href="/recipes/tags/float/">float</a>, <a href="/recipes/tags/range/">range</a>, <a href="/recipes/tags/spread/">spread</a>). </p> <p>See the recipe <a href="http://code.activestate.com/recipes/577878">here</a> for a description of the problem.</p> <p>This variant allows the user to choose between two APIs, either by supplying the count, start value and end value:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; list(spread(5, 1.0, end=2.0)) [1.0, 1.2, 1.4, 1.6, 1.8] </code></pre> <p>or the count, start value and step size:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; list(spread(5, 1.0, step=-0.25)) [1.0, 0.75, 0.5, 0.25, 0.0] </code></pre> <p>As before, the count argument specifies how many subdivisions are made. The optional argument <code>mode</code> selects whether the start and end values are included. By default, start is included and end is not, and exactly count values are returned.</p> Remove the real "input()" function from a current text mode Python 1.4.0 to 2.7.2 session... (Python) 2011-10-13T19:04:45-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577906-remove-the-real-input-function-from-a-current-text/ <p style="color: grey"> Python recipe 577906 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/input/">input</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/raw_input/">raw_input</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>). </p> <p>The single very powerful line of just the fifteen ASCII characters says it all...</p> <p>Read the code for more information...</p> <p>Tested on the platforms and versions inside the code...</p> <p>This is entirely Public Domain and hopefully it will be of use to many a Python coder...</p> <p>Enjoy finding simple solutions to often very difficult problems...</p> <p>Bazza, G0LCU...</p>