Popular recipes by Sridhar Ratnakumar http://code.activestate.com/recipes/users/4169511/2011-03-31T18:27:57-07:00ActiveState Code RecipesManage environment variables on Windows (Python) 2011-03-31T18:27:57-07:00Sridhar Ratnakumarhttp://code.activestate.com/recipes/users/4169511/http://code.activestate.com/recipes/577621-manage-environment-variables-on-windows/ <p style="color: grey"> Python recipe 577621 by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a> (<a href="/recipes/tags/environment/">environment</a>, <a href="/recipes/tags/pywin32/">pywin32</a>, <a href="/recipes/tags/windows/">windows</a>). Revision 7. </p> <p>This recipe facilitates getting and setting of both "user" and "system" environment variables on Windows. It uses PyWin32 (included in ActivePython) ... and works on both Python 2 and Python 3.</p> Safe unicode representation (Python) 2011-03-17T23:28:40-07:00Sridhar Ratnakumarhttp://code.activestate.com/recipes/users/4169511/http://code.activestate.com/recipes/577614-safe-unicode-representation/ <p style="color: grey"> Python recipe 577614 by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a> (<a href="/recipes/tags/unicode/">unicode</a>). </p> <p>Safely convert any given string type (text or binary) to unicode. You won't get UnicodeDecodeError error, at the cost of ignoring those errors during conversion, which is useful for debugging and logging. This recipe requires the <a href="http://code.activestate.com/pypm/six/">six</a> package.</p> Parse HTTP date-time string (Python) 2010-01-20T13:47:50-08:00Sridhar Ratnakumarhttp://code.activestate.com/recipes/users/4169511/http://code.activestate.com/recipes/577015-parse-http-date-time-string/ <p style="color: grey"> Python recipe 577015 by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a> (<a href="/recipes/tags/datetime/">datetime</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/parsing/">parsing</a>). </p> <p>This recipe will help you parse datetime strings returned by HTTP servers following the RFC 2616 standard (which <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3">supports three datetime formats</a>). Credit for this recipe goes to <a href="http://stackoverflow.com/questions/1471987/how-do-i-parse-an-http-date-string-in-python/1472336#1472336">ΤΖΩΤΖΙΟΥ</a>.</p> Logging to console .. without surprises (Python) 2009-06-25T13:12:55-07:00Sridhar Ratnakumarhttp://code.activestate.com/recipes/users/4169511/http://code.activestate.com/recipes/576819-logging-to-console-without-surprises/ <p style="color: grey"> Python recipe 576819 by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a> (<a href="/recipes/tags/logging/">logging</a>). Revision 3. </p> <p><code>logging.StreamHandler</code> is not the best way to log to console .. as it prints everything to <code>sys.stderr</code> by default. You can configure it to log to <code>sys.stdout</code> .. but that means even error/exception will be printed to <code>sys.stdout</code>.</p> lazy property (Python) 2009-04-26T18:10:55-07:00Sridhar Ratnakumarhttp://code.activestate.com/recipes/users/4169511/http://code.activestate.com/recipes/576720-lazy-property/ <p style="color: grey"> Python recipe 576720 by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a> (<a href="/recipes/tags/evaluation/">evaluation</a>, <a href="/recipes/tags/lazy/">lazy</a>, <a href="/recipes/tags/lazy_evaluation/">lazy_evaluation</a>). Revision 6. </p> <p>Python does not have lazy evaluation syntax features built-in, but fortunately decorators can be used with new-style classes to emulate such a feature. There are cases where one wants <code>foo.property</code> to return the actual property whose calculation takes significant amount of time.</p> <p>This recipe adapts the existing <code>property</code> to provide a <code>lazypropery</code> decorator that does this.</p> <p>See the first comment below for an example usage.</p> <p>Also see: <a href="http://en.wikipedia.org/wiki/Lazy_initialization">lazy initialization</a></p> tarfile.extractall with read access (Python) 2009-06-04T15:48:17-07:00Sridhar Ratnakumarhttp://code.activestate.com/recipes/users/4169511/http://code.activestate.com/recipes/576797-tarfileextractall-with-read-access/ <p style="color: grey"> Python recipe 576797 by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a> (<a href="/recipes/tags/tarfile/">tarfile</a>). </p> <p>Some tarballs have u-x set on directories .. this makes the program fail due to permissions. See <a href="http://bugs.python.org/issue6196" rel="nofollow">http://bugs.python.org/issue6196</a></p> Extract a compressed file (Python) 2009-04-09T08:19:34-07:00Sridhar Ratnakumarhttp://code.activestate.com/recipes/users/4169511/http://code.activestate.com/recipes/576714-extract-a-compressed-file/ <p style="color: grey"> Python recipe 576714 by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a> . Revision 2. </p> <p>This recipe can be used to extract any zip or tar.gz/tar.bz2 file.</p>