Popular recipes by geremy condra http://code.activestate.com/recipes/users/4170000/2009-05-27T17:43:56-07:00ActiveState Code RecipesC function decorator (Python)
2009-04-29T23:55:03-07:00geremy condrahttp://code.activestate.com/recipes/users/4170000/http://code.activestate.com/recipes/576731-c-function-decorator/
<p style="color: grey">
Python
recipe 576731
by <a href="/recipes/users/4170000/">geremy condra</a>
(<a href="/recipes/tags/cpp/">cpp</a>, <a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/function/">function</a>).
Revision 6.
</p>
<p>This recipe provides an easy-to-use, decorator-based solution to the problem of using functions from other languages, especially C, in Python. It takes advantage of Python's new annotations to provide simple type checking and automatic conversion. If you like it, you may also want to check out my <a href="http://code.activestate.com/recipes/576734/">C structure decorator</a></p>
Bitset (Python)
2009-05-04T16:37:02-07:00geremy condrahttp://code.activestate.com/recipes/users/4170000/http://code.activestate.com/recipes/576738-bitset/
<p style="color: grey">
Python
recipe 576738
by <a href="/recipes/users/4170000/">geremy condra</a>
(<a href="/recipes/tags/bits/">bits</a>, <a href="/recipes/tags/bytes/">bytes</a>).
</p>
<p>This is a simple Bitset type for Python. It implements the Sequence interface plus __setitem__, the set operations, and string and integer conversions.</p>
self-logging exceptions (Python)
2009-05-27T17:43:56-07:00geremy condrahttp://code.activestate.com/recipes/users/4170000/http://code.activestate.com/recipes/576781-self-logging-exceptions/
<p style="color: grey">
Python
recipe 576781
by <a href="/recipes/users/4170000/">geremy condra</a>
(<a href="/recipes/tags/exception/">exception</a>, <a href="/recipes/tags/logging/">logging</a>).
Revision 3.
</p>
<p>Pretty frequently I find myself needing to log my exceptions, and rather than produce a tangled mess of boilerplate code, I went ahead and put together this snippet to act as a base class for all those exceptions.</p>
C struct decorator (Python)
2009-05-02T11:27:22-07:00geremy condrahttp://code.activestate.com/recipes/users/4170000/http://code.activestate.com/recipes/576734-c-struct-decorator/
<p style="color: grey">
Python
recipe 576734
by <a href="/recipes/users/4170000/">geremy condra</a>
(<a href="/recipes/tags/cpp/">cpp</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/struct/">struct</a>).
Revision 3.
</p>
<p>Like my earlier <a href="http://code.activestate.com/recipes/576731/">C function decorator</a>, this recipe is designed to make it easier to interact with C by removing some of the boilerplate code from defining C structs in Python.</p>
Autogenerate API docs in Markdown (Python)
2009-04-28T23:11:26-07:00geremy condrahttp://code.activestate.com/recipes/users/4170000/http://code.activestate.com/recipes/576733-autogenerate-api-docs-in-markdown/
<p style="color: grey">
Python
recipe 576733
by <a href="/recipes/users/4170000/">geremy condra</a>
(<a href="/recipes/tags/documentation/">documentation</a>, <a href="/recipes/tags/markdown/">markdown</a>).
Revision 2.
</p>
<p>markdowndoc is a pydoc extension that allows you to autogenerate API docs for websites that use Markdown. We specifically developed it with Gitorious's wikis in mind, but it should work for other wikispaces and, of course, ActiveState. You can see a few examples of it <a href="http://gitorious.org/projects/python-markdown-api-builder/pages/Home">here</a>. </p>
Reevaluate functions when called, v3 (Python)
2009-05-14T15:18:41-07:00geremy condrahttp://code.activestate.com/recipes/users/4170000/http://code.activestate.com/recipes/576754-reevaluate-functions-when-called-v3/
<p style="color: grey">
Python
recipe 576754
by <a href="/recipes/users/4170000/">geremy condra</a>
(<a href="/recipes/tags/annotations/">annotations</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/function/">function</a>).
Revision 3.
</p>
<p>This small snippet came about as a result of this discussion on python-ideas, requesting a new syntax for dynamically reevaluating a function each time it is called.</p>
<p>It is a minor alteration of version 2 of this recipe that, instead of calling eval() on string annotations, simply requires that the annotations be callable and calls them at runtime.</p>
Reevaluate functions when called (Python)
2009-05-13T15:53:28-07:00geremy condrahttp://code.activestate.com/recipes/users/4170000/http://code.activestate.com/recipes/576751-reevaluate-functions-when-called/
<p style="color: grey">
Python
recipe 576751
by <a href="/recipes/users/4170000/">geremy condra</a>
(<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/function/">function</a>).
Revision 2.
</p>
<p>This small snippet came about as a result of <a href="http://groups.google.com/group/python-ideas/browse_thread/thread/92cf3f55919a8510/9e39950144daa9bb">this discussion</a> on python-ideas, requesting a new syntax for dynamically reevaluating a function each time it is called.</p>
<p>This snippet implements a simple decorator to do so without added syntax.</p>
Reevaluate functions when called, v2 (Python)
2009-05-14T15:10:51-07:00geremy condrahttp://code.activestate.com/recipes/users/4170000/http://code.activestate.com/recipes/576753-reevaluate-functions-when-called-v2/
<p style="color: grey">
Python
recipe 576753
by <a href="/recipes/users/4170000/">geremy condra</a>
(<a href="/recipes/tags/annotations/">annotations</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/function/">function</a>).
</p>
<p>As with version 1 of this recipe, it was sparked by a discussion on python-ideas about adding a special syntax to function signatures for reevaluating the arguments to a function at runtime. The below is a decorator and annotation based solution to this problem which stores the code to be evaluated as a string in the annotations, rather than reevaluating the entire function every time it is called.</p>