Most viewed recipes tagged "meta:loc=15"http://code.activestate.com/recipes/tags/meta:loc=15/views/2017-06-29T22:54:25-07:00ActiveState Code RecipesPure Python PDF to text converter (Python) 2007-04-12T11:05:10-07:00Dirk Holtwickhttp://code.activestate.com/recipes/users/636691/http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-converter/ <p style="color: grey"> Python recipe 511465 by <a href="/recipes/users/636691/">Dirk Holtwick</a> (<a href="/recipes/tags/text/">text</a>). Revision 2. </p> <p>This example shows how to extract text informations from a PDF file without the need of system dependent tools or code. Just use the pyPdf library from <a href="http://pybrary.net/pyPdf/" rel="nofollow">http://pybrary.net/pyPdf/</a></p> Checking whether a string contains a set of chars (Python) 2001-07-03T21:00:41-07:00Jürgen Hermannhttp://code.activestate.com/recipes/users/98061/http://code.activestate.com/recipes/65441-checking-whether-a-string-contains-a-set-of-chars/ <p style="color: grey"> Python recipe 65441 by <a href="/recipes/users/98061/">Jürgen Hermann</a> (<a href="/recipes/tags/text/">text</a>). Revision 2. </p> <p>While the find() and count() string functions can check for string occurences, there is no function to check on the occurence of a set of characters.</p> Insert a Text Box in a PDF page (fitz / PyMuPDF) (Python) 2017-06-29T22:54:25-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580809-insert-a-text-box-in-a-pdf-page-fitz-pymupdf/ <p style="color: grey"> Python recipe 580809 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/textbox/">textbox</a>). </p> <p>This method inserts text into a predefined rectangular area of a (new or existing) PDF page. Words are distributed across the available space, put on new lines when required etc. Line breaks and tab characters are respected / resolved. Text can be aligned in the box (left, center, right) and fonts can be freely chosen. The method returns a float indicating how vertical space is left over after filling the area.</p> Simple Average Calculation (Python) 2012-07-11T12:27:59-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/440625-simple-average-calculation/ <p style="color: grey"> Python recipe 440625 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>Here is a simple program that can average a list of numbers. I wrote this to introduce someone to the language that we all use and love. :D The program may be simple, but it shows how easily a simple but useful program can turn out to be.</p> changing file attributes on windows (Python) 2004-09-03T11:54:59-07:00John Nielsenhttp://code.activestate.com/recipes/users/135654/http://code.activestate.com/recipes/303343-changing-file-attributes-on-windows/ <p style="color: grey"> Python recipe 303343 by <a href="/recipes/users/135654/">John Nielsen</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>The win32api module offers SetFileAttributes whiles allows you to make changes to a file in windows. You can set a file to be read only, archive, hidden, etc. The function is simple and convenient to use.</p> Converts from decimal to any base ( between 2 and 26 ) (Python) 2011-02-24T00:33:07-08:00Shashwat Anandhttp://code.activestate.com/recipes/users/4172995/http://code.activestate.com/recipes/577586-converts-from-decimal-to-any-base-between-2-and-26/ <p style="color: grey"> Python recipe 577586 by <a href="/recipes/users/4172995/">Shashwat Anand</a> (<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/base/">base</a>). </p> <p>This function takes in any base-10 integer and returns the string representation of that number in its specified base-n form. The code was inspired from <a href="http://code.activestate.com/recipes/65212-convert-from-decimal-to-any-base-number/" rel="nofollow">http://code.activestate.com/recipes/65212-convert-from-decimal-to-any-base-number/</a> , thereby improving upon it.</p> Create a nested dictionary from os.walk (Python) 2011-09-26T23:38:24-07:00Andrew Clarkhttp://code.activestate.com/recipes/users/4179419/http://code.activestate.com/recipes/577879-create-a-nested-dictionary-from-oswalk/ <p style="color: grey"> Python recipe 577879 by <a href="/recipes/users/4179419/">Andrew Clark</a> (<a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/os_walk/">os_walk</a>). Revision 2. </p> <p>Creates a nested dictionary that represents a folder structure. Here is an example of what the resulting dictionary might look like:</p> <pre class="prettyprint"><code>{ "root": { "folder2": { "item2": None, "item1": None }, "folder1": { "subfolder1": { "item2": None, "item1": None }, "subfolder2": { "item3": None } } } } </code></pre> Automate CATIA V5 with Python and Pywin32 (Python) 2008-04-02T22:22:46-07:00Mustafa Görmezerhttp://code.activestate.com/recipes/users/2091634/http://code.activestate.com/recipes/347243-automate-catia-v5-with-python-and-pywin32/ <p style="color: grey"> Python recipe 347243 by <a href="/recipes/users/2091634/">Mustafa Görmezer</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 5. </p> <p>This is small application shows how to automate the CAD/PLM Software CATIA V5 via win32com. CATIA V5 must be installed and should be running when testing the application. Other examples you can find on <a href="http://win32com.goermezer.de/content/view/29/291/" rel="nofollow">http://win32com.goermezer.de/content/view/29/291/</a> .</p> Split string on capitalized/uppercase char (Python) 2005-10-12T03:24:34-07:00Graeme Glasshttp://code.activestate.com/recipes/users/2624411/http://code.activestate.com/recipes/440698-split-string-on-capitalizeduppercase-char/ <p style="color: grey"> Python recipe 440698 by <a href="/recipes/users/2624411/">Graeme Glass</a> (<a href="/recipes/tags/text/">text</a>). </p> <p>This function accepts a string and returns a string with whitespace(one space) inserted between words with leading capitalized letters.</p> slugify: make a string usable in a URL or filename (Python) 2010-06-07T04:11:55-07:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/577257-slugify-make-a-string-usable-in-a-url-or-filename/ <p style="color: grey"> Python recipe 577257 by <a href="/recipes/users/4173505/">Trent Mick</a> (<a href="/recipes/tags/ascii/">ascii</a>, <a href="/recipes/tags/django/">django</a>, <a href="/recipes/tags/filename/">filename</a>, <a href="/recipes/tags/slug/">slug</a>, <a href="/recipes/tags/slugify/">slugify</a>, <a href="/recipes/tags/url/">url</a>). Revision 2. </p> <p>"Slugify" a string so it is ascii, has only alphanumeric and hyphen characters. Useful for URLs and filenames. This is heavily based on the slugify in Django.</p> <p>Note: presumes that you've <code>import re</code>d higher up in your module.</p> Converty decimal/integer number to binary string in Python (Python) 2009-07-17T09:17:32-07:00Vishal Saprehttp://code.activestate.com/recipes/users/4166412/http://code.activestate.com/recipes/576847-converty-decimalinteger-number-to-binary-string-in/ <p style="color: grey"> Python recipe 576847 by <a href="/recipes/users/4166412/">Vishal Sapre</a> (<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/integer/">integer</a>, <a href="/recipes/tags/string/">string</a>). </p> <p>This is a very simple look-up based method for converting integer to binary string. In my tests, using 'timeit', its the fastest around. And with increasing value of input decimal number, it surpases any 'run time computation' based method doing the above.</p> Progress Bar for Console Programs as Iterator (Python) 2010-03-26T20:04:02-07:00Michael Grünewaldhttp://code.activestate.com/recipes/users/4172244/http://code.activestate.com/recipes/576986-progress-bar-for-console-programs-as-iterator/ <p style="color: grey"> Python recipe 576986 by <a href="/recipes/users/4172244/">Michael Grünewald</a> (<a href="/recipes/tags/console/">console</a>, <a href="/recipes/tags/cui/">cui</a>, <a href="/recipes/tags/progress/">progress</a>). Revision 6. </p> <p>A small proxy iterator showing a progress bar on the console. Only works with iterators that provide a length (i.e. <code>len(iterator)</code> must be defined).</p> Find the common beginning in a list of strings (Python) 2003-12-03T12:05:01-08:00Stephan Diehlhttp://code.activestate.com/recipes/users/774251/http://code.activestate.com/recipes/252177-find-the-common-beginning-in-a-list-of-strings/ <p style="color: grey"> Python recipe 252177 by <a href="/recipes/users/774251/">Stephan Diehl</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). Revision 3. </p> <p>I came up with this when I tried to implement some autocompletion feature. The problem is to find a common substring (beginning from the start) for all strings in a given list.</p> <p>I couldn't find an existing recipe that is doing this task, but I'm wondering if I just didn't look hard enough</p> extended great common divisor function (Python) 2006-03-14T21:02:28-08:00Robert W. Hankshttp://code.activestate.com/recipes/users/2808448/http://code.activestate.com/recipes/474129-extended-great-common-divisor-function/ <p style="color: grey"> Python recipe 474129 by <a href="/recipes/users/2808448/">Robert W. Hanks</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 6. </p> <p>the function find out the gcd(a,b) as a linear conbination of a anb b, ax+by=gcd(a,b). Please help me if you can.</p> Multi-character split (Tcl) 2001-09-10T10:07:20-07:00Jeff Hobbshttp://code.activestate.com/recipes/users/98167/http://code.activestate.com/recipes/68386-multi-character-split/ <p style="color: grey"> Tcl recipe 68386 by <a href="/recipes/users/98167/">Jeff Hobbs</a> (<a href="/recipes/tags/text/">text</a>). </p> <p>The split command splits a string based on each character that is in the splitString. This version handles the splitString as a combined string, splitting the string into constituent parts.</p> binascii.crc32 result to hex (Python) 2007-06-14T06:25:57-07:00Denis Barmenkovhttp://code.activestate.com/recipes/users/57155/http://code.activestate.com/recipes/521907-binasciicrc32-result-to-hex/ <p style="color: grey"> Python recipe 521907 by <a href="/recipes/users/57155/">Denis Barmenkov</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>Function becomes useful when we need hex value of crc32() result, even if it is negative.</p> win32com - Accessing AutoCAD entities (Python) 2005-08-30T13:48:52-07:00Ed Blakehttp://code.activestate.com/recipes/users/2492237/http://code.activestate.com/recipes/440493-win32com-accessing-autocad-entities/ <p style="color: grey"> Python recipe 440493 by <a href="/recipes/users/2492237/">Ed Blake</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>Autodesk's AutoCAD drafting software has for a number of versions included an increasingly complete COM interface. Using the Python win32com modules we have been able to automate some aspects the software; unfortunately because of the organization of the interface certain methods and properties were inaccessible from Python. In recent versions of the win32 modules a new function has been added though: win32com.client.CastTo(). By casting our objects as the correct type we now have access to much of the object model that used to be unreachable.</p> <p>In this example we search the ModelSpace collection for text objects. Once found we then cast them and alter one of the text specific properties. To test this code open AutoCAD and in a blank file add at least one dtext object with 'Spam' as its value.</p> Calculating e using Continued Fraction (Python) 2013-09-02T18:49:53-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578653-calculating-e-using-continued-fraction/ <p style="color: grey"> Python recipe 578653 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>Calculating e using Continued Fraction</p> 'with' statement for StringIO (Python) 2009-02-24T00:01:16-08:00sridhttp://code.activestate.com/recipes/users/4053089/http://code.activestate.com/recipes/576650-with-statement-for-stringio/ <p style="color: grey"> Python recipe 576650 by <a href="/recipes/users/4053089/">srid</a> (<a href="/recipes/tags/stringio/">stringio</a>, <a href="/recipes/tags/with_statement/">with_statement</a>). Revision 3. </p> <p>NOTE: Consider this recipe obsolete. Instead use <code>contextlib.closing</code> (see comment below).</p> <p>This contextmanager adds 'with' statement support for StringIO. Peruse the following simple example:</p> <pre class="prettyprint"><code>with StringIO() as sio: function_accepting_file_handle(sio) print sio.getvalue() </code></pre> Add account to group in Active Directory (Python) 2007-04-03T22:13:42-07:00Thomas Dimsonhttp://code.activestate.com/recipes/users/4046694/http://code.activestate.com/recipes/511447-add-account-to-group-in-active-directory/ <p style="color: grey"> Python recipe 511447 by <a href="/recipes/users/4046694/">Thomas Dimson</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 2. </p> <p>This code will add a previously created user to a previously created group in Active Directory.</p>