Popular recipes by Sami Hangaslammi http://code.activestate.com/recipes/users/118800/2004-06-18T10:57:33-07:00ActiveState Code RecipesSafe Expression Evaluation (Python)
2004-06-14T09:56:27-07:00Sami Hangaslammihttp://code.activestate.com/recipes/users/118800/http://code.activestate.com/recipes/286134-safe-expression-evaluation/
<p style="color: grey">
Python
recipe 286134
by <a href="/recipes/users/118800/">Sami Hangaslammi</a>
(<a href="/recipes/tags/programs/">programs</a>).
Revision 3.
</p>
<p>Often, we might want to let (untrusted) users input simple Python expressions and evaluate them, but the eval-function in Python is unsafe. The restricted execution model in the rexec module is deprecated, so we need another way ensure only "safe" expressions will be evaluted: analyzing bytecodes.</p>
Function Decorators by Hacking Bytecodes (Python)
2004-06-18T10:57:33-07:00Sami Hangaslammihttp://code.activestate.com/recipes/users/118800/http://code.activestate.com/recipes/286147-function-decorators-by-hacking-bytecodes/
<p style="color: grey">
Python
recipe 286147
by <a href="/recipes/users/118800/">Sami Hangaslammi</a>
(<a href="/recipes/tags/programs/">programs</a>).
Revision 2.
</p>
<p>Wether or not PEP 318 makes it to Python 2.4, you can experiment with an alternative decorator syntax in Python 2.3 by hacking with bytecodes.</p>
Finding out the number of values the caller is expecting (Python)
2004-05-21T13:13:35-07:00Sami Hangaslammihttp://code.activestate.com/recipes/users/118800/http://code.activestate.com/recipes/284742-finding-out-the-number-of-values-the-caller-is-exp/
<p style="color: grey">
Python
recipe 284742
by <a href="/recipes/users/118800/">Sami Hangaslammi</a>
(<a href="/recipes/tags/shortcuts/">shortcuts</a>).
Revision 4.
</p>
<p>Sometimes you might want to make a function behave differently if the caller is expecting one or several values (e.g. x=func() versus x,y=func()). The expecting() function lets the function implementer find out how many values the caller wants as a function result.</p>
Case-insensitive Dictionary (Python)
2001-07-23T05:50:04-07:00Sami Hangaslammihttp://code.activestate.com/recipes/users/118800/http://code.activestate.com/recipes/66315-case-insensitive-dictionary/
<p style="color: grey">
Python
recipe 66315
by <a href="/recipes/users/118800/">Sami Hangaslammi</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>A dictionary that has case-insensitive keys.</p>
ReadWriteLock (Python)
2001-07-25T15:04:51-07:00Sami Hangaslammihttp://code.activestate.com/recipes/users/118800/http://code.activestate.com/recipes/66426-readwritelock/
<p style="color: grey">
Python
recipe 66426
by <a href="/recipes/users/118800/">Sami Hangaslammi</a>
(<a href="/recipes/tags/threads/">threads</a>).
</p>
<p>A lock object that allows many simultaneous "read-locks", but only one "write-lock".</p>
Iterator Utilities (Python)
2001-07-30T19:30:23-07:00Sami Hangaslammihttp://code.activestate.com/recipes/users/118800/http://code.activestate.com/recipes/66448-iterator-utilities/
<p style="color: grey">
Python
recipe 66448
by <a href="/recipes/users/118800/">Sami Hangaslammi</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 2.
</p>
<p>A collection of small utility functions for iterators (all functions can also be used with normal sequences). Among other things, the module provides generator ("lazy") versions of the built-in sequence-manipulation functions. The generators can be combined to produce a more specialised iterator.</p>
Converting Between Different Naming Convetions (Python)
2001-07-09T05:05:29-07:00Sami Hangaslammihttp://code.activestate.com/recipes/users/118800/http://code.activestate.com/recipes/66009-converting-between-different-naming-convetions/
<p style="color: grey">
Python
recipe 66009
by <a href="/recipes/users/118800/">Sami Hangaslammi</a>
(<a href="/recipes/tags/text/">text</a>).
</p>
<p>These short functions convert identifier names between the most common naming conventions: CapitalizedWords, mixedCase and under_scores.</p>