Popular recipes by Artur Siekielski http://code.activestate.com/recipes/users/4177664/2011-05-19T17:54:43-07:00ActiveState Code RecipesCheck for package updates on PyPI (works best in pip+virtualenv) (Python) 2011-05-19T17:54:43-07:00Artur Siekielskihttp://code.activestate.com/recipes/users/4177664/http://code.activestate.com/recipes/577708-check-for-package-updates-on-pypi-works-best-in-pi/ <p style="color: grey"> Python recipe 577708 by <a href="/recipes/users/4177664/">Artur Siekielski</a> (<a href="/recipes/tags/pip/">pip</a>, <a href="/recipes/tags/pypi/">pypi</a>, <a href="/recipes/tags/virtualenv/">virtualenv</a>). </p> <p>Pip has an option to upgrade a package (_pip install -U_), however it always downloads sources even if there is already a newest version installed. If you want to check updates for all installed packages then some scripting is required.</p> <p>This script checks if there is a newer version on PyPI for every installed package. It only prints information about available version and doesn't do any updates. Example output:</p> <pre class="prettyprint"><code>distribute 0.6.15 0.6.16 available Baker 1.1 up to date Django 1.3 up to date ipython 0.10.2 up to date gunicorn 0.12.1 0.12.2 available pyprof2calltree 1.1.0 up to date profilestats 1.0.2 up to date mercurial 1.8.3 up to date </code></pre> Line-oriented processing in Python from command line (like AWK) (Python) 2011-04-14T19:49:16-07:00Artur Siekielskihttp://code.activestate.com/recipes/users/4177664/http://code.activestate.com/recipes/577656-line-oriented-processing-in-python-from-command-li/ <p style="color: grey"> Python recipe 577656 by <a href="/recipes/users/4177664/">Artur Siekielski</a> (<a href="/recipes/tags/awk/">awk</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/shell/">shell</a>). </p> <p>A very simple but powerful shell script which enables writing ad-hoc Python scripts for processing line-oriented input. It executes the following code template:</p> <pre class="prettyprint"><code>$INIT for line in sys.stdin: $LOOP $END </code></pre> <p>where $INIT, $LOOP and $END code blocks are given from command line. If only one argument is given, then $INIT and $END are empty. If two arguments are given, $END is empty.</p> <p>Examples (script is saved as 'pyk' in the $PATH):</p> <ul> <li>"wc -l" replacement: $ cat file | pyk 'c=0' 'c+=1' 'print c'</li> <li>grep replacement: $ cat file | pyk 'import re' 'if re.search("\d+", line): print line'</li> <li>adding all numbers: $ seq 1 10 | pyk 's=0' 's+=int(line)' 'print s'</li> <li>prepending lines with it's length: $ cat file | pyk 'print len(line), line'</li> <li>longest file name: $ ls -1 | pyk 'longest=""' 'if len(line) &gt; len(longest): longest=line' 'print longest'</li> <li>number of unique words in a document: $ pyk 'words=[]' 'words.extend(line.split())' 'print "All words: {}, unique: {}".format(len(words), len(set(words))'</li> </ul>