Popular recipes tagged "meta:loc=47"http://code.activestate.com/recipes/tags/meta:loc=47/2016-11-07T20:28:01-08:00ActiveState Code RecipesBatch conversion of text files to PDF with fileinput and xtopdf (Python)
2016-11-07T20:28:01-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580715-batch-conversion-of-text-files-to-pdf-with-fileinp/
<p style="color: grey">
Python
recipe 580715
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/batch/">batch</a>, <a href="/recipes/tags/batchmode/">batchmode</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/text_processing/">text_processing</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to do a batch conversion of the content of multiple text files into a single PDF file, with a) an automatic page break after the content of each text file (in the PDF output), b) page numbering, and c) a header and footer on each page.</p>
<p>It uses the fileinput module (part of the Python standard library), and xtopdf, a Python library for conversion of other formats to PDF.</p>
<p>xtopdf is available here: <a href="https://bitbucket.org/vasudevram/xtopdf" rel="nofollow">https://bitbucket.org/vasudevram/xtopdf</a></p>
<p>and a guide to installing and using xtopdf is here:</p>
<p><a href="http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html" rel="nofollow">http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html</a></p>
<p>Here is a sample run of the program:</p>
<p>python BTTP123.pdf text1.txt text2.txt text3.txt</p>
<p>This will read the content from the three text files specified and write it into the PDF file specified, neatly formatted.</p>
Routine to i18nify any word (Python)
2016-05-19T18:41:26-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580662-routine-to-i18nify-any-word/
<p style="color: grey">
Python
recipe 580662
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/i18n/">i18n</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/strings/">strings</a>, <a href="/recipes/tags/text_processing/">text_processing</a>).
</p>
<p>This recipe shows a routine and a driver program that lets you "i18nify" any word, similar to how the word "internationalization" is shortened to "i18n", and "localization" to "l10n".</p>
How to read an input from .txt file in python and the output in .xml (Python)
2014-12-20T00:16:32-08:00Varsha Hollahttp://code.activestate.com/recipes/users/4191376/http://code.activestate.com/recipes/578985-how-to-read-an-input-from-txt-file-in-python-and-t/
<p style="color: grey">
Python
recipe 578985
by <a href="/recipes/users/4191376/">Varsha Holla</a>
(<a href="/recipes/tags/python3_1/">python3_1</a>).
Revision 3.
</p>
<p>Hey, I have a .txt file, I want to read the file and the output should be in .xml format.
Any suggestions? </p>
Cycling a sequence (Python)
2014-09-20T19:20:46-07:00Tomas Nordinhttp://code.activestate.com/recipes/users/4189558/http://code.activestate.com/recipes/578942-cycling-a-sequence/
<p style="color: grey">
Python
recipe 578942
by <a href="/recipes/users/4189558/">Tomas Nordin</a>
(<a href="/recipes/tags/cyclic_iterator/">cyclic_iterator</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/iterable/">iterable</a>, <a href="/recipes/tags/iterator/">iterator</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>A post-it function to cycle through some sequence. Better use itertools.cycle if for any iterable.</p>
Publish Berkeley DB data to PDF with xtopdf (Python)
2014-01-24T17:57:21-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578814-publish-berkeley-db-data-to-pdf-with-xtopdf/
<p style="color: grey">
Python
recipe 578814
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/bsddb/">bsddb</a>, <a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to convert the data stored in a Berkeley DB database to PDF, using the xtopdf toolkit for PDF creation.
It should work on either Linux/Unix or Windows.</p>
Monotonic local time. And sandwich. (Python)
2013-01-03T08:28:36-08:00Oren Tiroshhttp://code.activestate.com/recipes/users/2033964/http://code.activestate.com/recipes/578270-monotonic-local-time-and-sandwich/
<p style="color: grey">
Python
recipe 578270
by <a href="/recipes/users/2033964/">Oren Tirosh</a>
(<a href="/recipes/tags/daylight/">daylight</a>, <a href="/recipes/tags/dst/">dst</a>, <a href="/recipes/tags/time/">time</a>).
</p>
<p>A Mutton, Lettuce and Tomato sandwich is generally agreed to be the greatest thing in the world. But a different kind of MLT comes in at a close second: Monotonic Local Time. This is a time value in your local timezone that takes care of that annoying hour that happens once a year where time goes backwards. It works by extending the previous day by a couple of hours (24, 25 etc) until after the switch.</p>
Bezier Curve using De Casteljau algorithm (Python)
2011-11-25T02:33:54-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577961-bezier-curve-using-de-casteljau-algorithm/
<p style="color: grey">
Python
recipe 577961
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>).
</p>
<p>Draws a random Bezier Curve using De Casteljau algorithm.</p>
Converts doc files into text files on Windows platform (Python)
2012-05-08T06:39:43-07:00Shao-chuan Wanghttp://code.activestate.com/recipes/users/4168519/http://code.activestate.com/recipes/578121-converts-doc-files-into-text-files-on-windows-plat/
<p style="color: grey">
Python
recipe 578121
by <a href="/recipes/users/4168519/">Shao-chuan Wang</a>
(<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/pythoncom/">pythoncom</a>, <a href="/recipes/tags/word/">word</a>).
</p>
<p><strong>READ BEFORE YOU USE THE CODE</strong></p>
<p><strong>Requirements</strong></p>
<ol>
<li>Windows platform</li>
<li>Python 2.7</li>
<li>pywin32, <a href="http://sourceforge.net/projects/pywin32/" rel="nofollow">http://sourceforge.net/projects/pywin32/</a></li>
<li>Word application installed on running machine</li>
</ol>
Bless Classes into Singletons (Python)
2011-09-21T05:34:52-07:00Anand B Pillaihttp://code.activestate.com/recipes/users/4169530/http://code.activestate.com/recipes/577875-bless-classes-into-singletons/
<p style="color: grey">
Python
recipe 577875
by <a href="/recipes/users/4169530/">Anand B Pillai</a>
(<a href="/recipes/tags/metaclasses/">metaclasses</a>, <a href="/recipes/tags/patterns/">patterns</a>, <a href="/recipes/tags/singleton/">singleton</a>).
</p>
<p>A pattern using metaclasses for "blessing" classes into Singletons.</p>
Named Values (Python)
2011-07-28T00:23:34-07:00Nick Coghlanhttp://code.activestate.com/recipes/users/2035254/http://code.activestate.com/recipes/577810-named-values/
<p style="color: grey">
Python
recipe 577810
by <a href="/recipes/users/2035254/">Nick Coghlan</a>
.
Revision 2.
</p>
<p>NamedValue is a mixin class that modifies the signature of the class constructor to accept a name as the first positional argument and modifies repr() to display the name without affecting the result of str() (even for peer classes that rely on the str->repr fallback for their str implementation).</p>
Pendulum Simulation with Turtle (Python)
2011-01-27T22:59:54-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577553-pendulum-simulation-with-turtle/
<p style="color: grey">
Python
recipe 577553
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/demonstration/">demonstration</a>, <a href="/recipes/tags/simulation/">simulation</a>, <a href="/recipes/tags/turtle/">turtle</a>).
</p>
<p>This program was written per R.T.Giles's second assignment in 10COF180 (November 25, 2010). A student under his instruction wanted help writing a program, and while not required, a GUI was placed on the program's output to visually demonstrate what was taking place within the program. The recipe below provides a simple simulation of a undamped pendulum and produces a visual representation for about thirty seconds. The code could be greatly improved but gives a demonstration of what a few turtle commands can do in Python. Very little code must be written to produce graphics on the computer screen.</p>
setdict (Python)
2010-11-27T03:00:28-08:00thom nealehttp://code.activestate.com/recipes/users/4176069/http://code.activestate.com/recipes/577471-setdict/
<p style="color: grey">
Python
recipe 577471
by <a href="/recipes/users/4176069/">thom neale</a>
(<a href="/recipes/tags/dict/">dict</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/set/">set</a>).
</p>
<p>Set-like operations for dictionaries</p>
Tkinter Splash Screen (Python)
2010-06-21T18:09:06-07:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577271-tkinter-splash-screen/
<p style="color: grey">
Python
recipe 577271
by <a href="/recipes/users/4174115/">Sunjay Varma</a>
(<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/screen/">screen</a>, <a href="/recipes/tags/splash/">splash</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>I wanted to mess around with the overrideredirect function of the window manager, and ended up making a pretty good Python Tkinter splash screen. :)</p>
<p>Just run it for a demo.</p>
<p>There are instructions and more info in the script</p>
Maclaurin's_series_cosh (Python)
2010-07-07T12:01:34-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577286-maclaurins_series_cosh/
<p style="color: grey">
Python
recipe 577286
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>).
Revision 2.
</p>
<p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p>
<p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices.</p>
<p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p>
<p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p>
<p>Hyperbolic functions are very common in the engineering field and they are related to trigonometric functions, thus, trigonometric functions could be expressed in terms of exponential(x)
The hyperbolic cosine cosh(x) =(e^x + e^-x)/2.</p>
Maclaurin's_series_sinh (Python)
2010-07-07T12:08:34-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577288-maclaurins_series_sinh/
<p style="color: grey">
Python
recipe 577288
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>).
</p>
<p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p>
<p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices.</p>
<p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p>
<p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p>
<p>Hyperbolic functions are very common in the engineering field and they are related to trigonometric functions, thus, trigonometric functions could be expressed in terms of exponential(x)
The hyperbolic sine sinh(x) = (e^x - e^-x)/2.</p>
Find Prime Numbers in python (Python)
2010-06-12T08:22:40-07:00Giannis Fysakishttp://code.activestate.com/recipes/users/4174072/http://code.activestate.com/recipes/577259-find-prime-numbers-in-python/
<p style="color: grey">
Python
recipe 577259
by <a href="/recipes/users/4174072/">Giannis Fysakis</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/primality_testing/">primality_testing</a>, <a href="/recipes/tags/prime/">prime</a>, <a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>).
Revision 2.
</p>
<p>The algorithm is based on the idea <br />
that the next larger prime after one prime is the sum of the two smaller previous minus three prime numbers back.
For the first five prime numbers 2,3,5,7,11 this pattern is not true also it is not true if the number is a composite number (including of course if the number's square root is integer). </p>
<p>Example
trying to find the tenth prime</p>
<p>so lets play with numbers 17(minus 3 from Next,position 7), 19(minus 2 from Next,position 8), 23(minus 1 from Next,position 9) and number Next at position 10 :</p>
<p>hmmm ... if we add 19 and 23 we get 42, but 42 minus 17 equals 25 which isn't a prime :(</p>
<p>In order to correct this we assume that 25 is the next prime number ( temporary holding the tenth position)
finally to get the real Next prime number we take 23 + 25 = 48 , we subtract 19 and we get 29 which finally it takes the tenth position ( because it deserves it :P)</p>
Update Source Directories (Python)
2009-07-21T23:40:53-07:00Alia Khourihttp://code.activestate.com/recipes/users/4169084/http://code.activestate.com/recipes/576853-update-source-directories/
<p style="color: grey">
Python
recipe 576853
by <a href="/recipes/users/4169084/">Alia Khouri</a>
(<a href="/recipes/tags/bzr/">bzr</a>, <a href="/recipes/tags/git/">git</a>, <a href="/recipes/tags/hg/">hg</a>, <a href="/recipes/tags/svn/">svn</a>, <a href="/recipes/tags/vcs/">vcs</a>).
</p>
<p>A convenience script to update a pre-specified folder containing
subversion, mercurial, bazaar, and/or git source folders</p>
<p>To use it: </p>
<ul>
<li><p>change the 'src' variable below to point to your source folder</p></li>
<li><p>name this script to something appropriate (I call it 'update')</p></li>
<li><p>put it into a directory on your PATH</p></li>
</ul>
iterator with context (Python)
2008-02-04T15:10:05-08:00Guillaume Coffinhttp://code.activestate.com/recipes/users/4122066/http://code.activestate.com/recipes/544296-iterator-with-context/
<p style="color: grey">
Python
recipe 544296
by <a href="/recipes/users/4122066/">Guillaume Coffin</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>an iterator that keeps a list of the next and previous items in a fixed length window. For instance, one can obtain the 10 items that are ahead the current one.</p>
AST Pretty Printer (Python)
2007-10-09T11:42:44-07:00Martin Blaishttp://code.activestate.com/recipes/users/1643324/http://code.activestate.com/recipes/533145-ast-pretty-printer/
<p style="color: grey">
Python
recipe 533145
by <a href="/recipes/users/1643324/">Martin Blais</a>
(<a href="/recipes/tags/debugging/">debugging</a>).
</p>
<p>A function that outputs a human-readable version of a Python AST.</p>
Semi-automatic resource management with AutoClose (Python)
2009-11-18T21:37:55-08:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/523007-semi-automatic-resource-management-with-autoclose/
<p style="color: grey">
Python
recipe 523007
by <a href="/recipes/users/1122360/">Michele Simionato</a>
(<a href="/recipes/tags/oop/">oop</a>).
Revision 4.
</p>
<p>This recipe provides a semi-automatic mechanism to close resources.</p>