Popular recipes tagged "meta:loc=196"http://code.activestate.com/recipes/tags/meta:loc=196/2016-04-10T22:43:57-07:00ActiveState Code RecipesHow to parse a table in a PDF document (Python)
2016-04-10T22:43:57-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580635-how-to-parse-a-table-in-a-pdf-document/
<p style="color: grey">
Python
recipe 580635
by <a href="/recipes/users/4193772/">Jorj X. McKie</a>
(<a href="/recipes/tags/cbz/">cbz</a>, <a href="/recipes/tags/epub/">epub</a>, <a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/openxps/">openxps</a>, <a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>, <a href="/recipes/tags/table/">table</a>, <a href="/recipes/tags/xps/">xps</a>).
Revision 4.
</p>
<p>A Python function that converts a table contained in a page of a PDF (or OpenXPS, EPUB, CBZ, XPS) document to a matrix-like Python object (list of lists of strings).</p>
Dragon Lexical Analyzer (Python)
2010-09-01T14:49:37-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/577380-dragon-lexical-analyzer/
<p style="color: grey">
Python
recipe 577380
by <a href="/recipes/users/4076953/">Jack Trainor</a>
(<a href="/recipes/tags/educational/">educational</a>, <a href="/recipes/tags/lexical_analyzer/">lexical_analyzer</a>, <a href="/recipes/tags/parsing/">parsing</a>).
Revision 2.
</p>
<p>The lexical analyzer from "Compliers: Principles, Techniques and Tools," Chapter 2, by Aho, Sethi, Ullman (1986) implemented in Python.</p>
Download chromium browser nightly builds for any OS (with proxy support) (Python)
2014-07-05T18:47:47-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/577162-download-chromium-browser-nightly-builds-for-any-o/
<p style="color: grey">
Python
recipe 577162
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/chrome/">chrome</a>, <a href="/recipes/tags/chromium/">chromium</a>, <a href="/recipes/tags/download/">download</a>, <a href="/recipes/tags/unzip/">unzip</a>).
Revision 19.
</p>
<p>Downloads the latest Chromium browser build from <a href="http://commondatastorage.googleapis.com/chromium-browser-continuous/" rel="nofollow">http://commondatastorage.googleapis.com/chromium-browser-continuous/</a> using urllib2 or wget (with Python versions below 2.5) and unzips the downloaded zip file to a predefined folder.</p>
<p>To use a custom proxy define the <code>HTTP_PROXY</code> system variable.</p>
<p>The script will figure out the OS but you can also pass the platform as the first parameter (one of <code>win32, linux, linux64, mac</code>).</p>
<p><em>Prerequisites (!! only for Python versions below 2.5):</em></p>
<ul>
<li><p><code>wget</code> - usually already installed on most linux systems. Windows users can get it <a href="http://gnuwin32.sourceforge.net/packages/wget.htm">here</a>.</p></li>
<li><p><code>unzip</code> - used for unpacking the archive; usually already installed on most linux systems. Windows users can get it <a href="http://gnuwin32.sourceforge.net/packages/unzip.htm">here</a>.</p></li>
</ul>
<p>Both <code>wget</code> and <code>unzip</code> should be available in PATH (for Python 2.5+ native Python modules are used).</p>
<p>For most Linux distros this script does not make much sense since the built-in package managers do a better job of managing chromium builds and dependencies, but it still can be useful if you are using a stable Chromium build but would like to be able to test the nightly builds too.</p>
<p>For OSX an additional installation step will be performed using the <code>install.sh</code> that is included in the OSX build. The OSX installer will copy the package to <code>~/Applications/Chromium</code>, and set some permissions that are required for Chromium to run. Running the unpacked zip without doing the installation will most likely will not work because of missing executable permissions on some files.</p>
Fuzzy matching dictionary (Python)
2006-03-18T11:23:25-08:00Mark Mc Mahonhttp://code.activestate.com/recipes/users/2819006/http://code.activestate.com/recipes/475148-fuzzy-matching-dictionary/
<p style="color: grey">
Python
recipe 475148
by <a href="/recipes/users/2819006/">Mark Mc Mahon</a>
(<a href="/recipes/tags/search/">search</a>).
</p>
<p>This is more an ease of use subclass of dict - rather then one that uses a lot of dict features.</p>
<p>If your requested item is in the dictionary (with a key that hashes the same) then it acts as a more or less normal dictionary.</p>
<p>If on the other hand you are looking for a string that is similar to a key in the dictionary, then the class iterates over all the keys and finds the one that is the closest match.</p>
filetail.py (Python)
2005-07-12T11:41:30-07:00Jonathan Moorehttp://code.activestate.com/recipes/users/2516431/http://code.activestate.com/recipes/436477-filetailpy/
<p style="color: grey">
Python
recipe 436477
by <a href="/recipes/users/2516431/">Jonathan Moore</a>
(<a href="/recipes/tags/files/">files</a>).
</p>
<p>doing a tail -f on a system log and handling log rotation (File::Tail for python)</p>
Yet another reinvention of a Python HTML generation mechanism (Python)
2005-11-22T07:25:44-08:00Josiah Carlsonhttp://code.activestate.com/recipes/users/1241800/http://code.activestate.com/recipes/440563-yet-another-reinvention-of-a-python-html-generatio/
<p style="color: grey">
Python
recipe 440563
by <a href="/recipes/users/1241800/">Josiah Carlson</a>
(<a href="/recipes/tags/web/">web</a>).
Revision 3.
</p>
<p>The other day I was complaining about writing html, forms, etc., for Python cgi and/or web programming. I had pointed out a selection of three examples, the first of which ended up being very much like Nevow.stan . Thinking a bit about it, I realized that stan had issues in that you couldn't really re-use pre-defined tags with attributes via map, and keyword arguments were just too darn convenient to swap the calling and getitem syntax.</p>
<p>Instead, I hacked together a mechanism that supports:
T.tagname("content", T.tagname(...), ..., attr1='value', ...)
T.tagname(attr1='value', ...)("content", T.tagname(...), ...)
x = T.tagname(attr1='value', ...)
y = T.tagname(*map(x, ['content', ...]))
... and many other options.</p>
<p>Essentially, you can mix and match calls as much as you want, with three memory and sanity saving semantics:
1. Creating a new tag object via T.tagname, or any call of such, will create a shallow copy of the object you are accessing.
2. smallred = T.font(size='-1', color='red');bigred = smallred(size='+1') Works exactly the way you expect it to. If it doesn't work the way you expect it to, then your expectations are confused.
3. If you are adding content that sites within the tag, the content is replaced, not updated, like attributes.</p>
<p>This simple version handles auto-indentation of content as necessary (or desireable), auto-escaping of text elements, and includes an (I believe) nearly complete listing of entities which don't require closing tags.</p>
<p>I don't know where this is going, whether it can or will expand into something more, or what, but I believe what I have managed to hack together is better than other similar packages available elsewhere (including this recipe over here <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/366000" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/366000</a> , which I discovered after writing my own). Funny how these things work out. Astute observers will note that I borrow nevow.stan's meme of using T.tagname for generating tag objects.</p>
Simple File Splitter/Combiner module (Python)
2003-11-06T07:14:42-08:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/224800-simple-file-splittercombiner-module/
<p style="color: grey">
Python
recipe 224800
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/files/">files</a>).
Revision 4.
</p>
<p>This module can be used to split any file, text or binary
to equal sized chunks. It can also combine the chunks back
to recreate the original file.</p>
Finding the convex hull of a set of 2D points (Python)
2001-08-17T00:50:23-07:00Dinu Ghermanhttp://code.activestate.com/recipes/users/124101/http://code.activestate.com/recipes/66527-finding-the-convex-hull-of-a-set-of-2d-points/
<p style="color: grey">
Python
recipe 66527
by <a href="/recipes/users/124101/">Dinu Gherman</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>This simple code calculates the convex hull of a set of 2D points
and generates EPS files to visualise them. The algorithm was taken
from a textbook on Computional Geometry.</p>