Popular recipes tagged "conversion"http://code.activestate.com/recipes/tags/conversion/2016-12-06T20:37:30-08:00ActiveState Code RecipesConvert wildcard text files to PDF with xtopdf (e.g. report*.txt) (Python) 2016-12-06T20:37:30-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580727-convert-wildcard-text-files-to-pdf-with-xtopdf-eg-/ <p style="color: grey"> Python recipe 580727 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/globbing/">globbing</a>, <a href="/recipes/tags/patterns/">patterns</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/text_processing/">text_processing</a>, <a href="/recipes/tags/wildcard/">wildcard</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to convert all text files matching a filename wildcard to PDF, using the xtopdf PDF creation toolkit. For example, if you specify report<em>.txt as the wildcard, all files in the current directory that match report</em>.txt, will be converted to PDF, each in a separate PDF file. The original text files are not changed.</p> <p>Here is a guide to installing and using xtopdf:</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>More details on running the program, and sample output, are available here:</p> <p><a href="http://jugad2.blogspot.in/2016/12/xtopdf-wildcard-text-files-to-pdf-with.html" rel="nofollow">http://jugad2.blogspot.in/2016/12/xtopdf-wildcard-text-files-to-pdf-with.html</a></p> Batch 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> Read CSV with D and write it to PDF with Python (Python) 2016-10-26T17:49:00-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580710-read-csv-with-d-and-write-it-to-pdf-with-python/ <p style="color: grey"> Python recipe 580710 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to read data from a CSV file with a D program and write that data to a PDF file with a Python program - all in a single command-line invocation (after writing the individual programs, of course).</p> <p>It requires the xtopdf toolkit, which you can get from:</p> <p><a href="https://bitbucket.org/vasudevram/xtopdf" rel="nofollow">https://bitbucket.org/vasudevram/xtopdf</a></p> <p>Instructions for installing xtopdf:</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>xtopdf in turn requires the open source version of the ReportLab toolkit, which you can get from:</p> <p><a href="http://www.reportlab.com/ftp" rel="nofollow">http://www.reportlab.com/ftp</a> (<a href="http://www.reportlab.com/ftp/reportlab-1.21.1.tar.gz%29" rel="nofollow">http://www.reportlab.com/ftp/reportlab-1.21.1.tar.gz)</a></p> <p>It also requires the DMD compiler to compile the D program - this was the version used:</p> <p>DMD32 D Compiler v2.071.2</p> Put Peewee ORM data to PDF with xtopdf (Python) 2016-09-29T18:04:57-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580704-put-peewee-orm-data-to-pdf-with-xtopdf/ <p style="color: grey"> Python recipe 580704 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/converter/">converter</a>, <a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/orm/">orm</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/peewee/">peewee</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/sqlite/">sqlite</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how some basics of how to fetch data from database tables managed by the Peewee ORM (a lightweight expressive ORM for Python) and write that data, formatted, to a PDF file. The recipe uses Python, the Peewee ORM and the xtopdf toolkit for PDF creation.</p> Generate a PDF cheat sheet for converting 0 to 255 between bin / oct / dec / hex (Python) 2016-10-10T20:40:48-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580706-generate-a-pdf-cheat-sheet-for-converting-0-to-255/ <p style="color: grey"> Python recipe 580706 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/hexadecimal/">hexadecimal</a>, <a href="/recipes/tags/octal/">octal</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/utility/">utility</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to generate a PDF cheat sheet, that contains a table for conversion of the numbers 0 to 255 (the numbers that can fit in one byte) between binary, octal, decimal and hexadecimal representations. The table has four columns, one for each of those bases, and 256 rows, for the numbers 0 to 255.</p> <p>TO use the table, you can look for a number, say in decimal, in the Dec(imal) column (or use the search function of your PDF viewer), then when you find it in some row, just look at the other 3 columns in that row, to find the value of that number in binary, octal and hexadecimal. And use the same procedure if starting with a number in any of the other three bases.</p> Bytes-to-human / human-to-bytes converter (Python) 2012-02-02T16:09:52-08:00Giampaolo Rodolàhttp://code.activestate.com/recipes/users/4178764/http://code.activestate.com/recipes/578019-bytes-to-human-human-to-bytes-converter/ <p style="color: grey"> Python recipe 578019 by <a href="/recipes/users/4178764/">Giampaolo Rodolà</a> (<a href="/recipes/tags/bytes/">bytes</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/converter/">converter</a>, <a href="/recipes/tags/human/">human</a>, <a href="/recipes/tags/humanize/">humanize</a>, <a href="/recipes/tags/string/">string</a>). Revision 15. </p> <p>Here goes.</p> Publish SQLite data to PDF using named tuples (Python) 2015-02-24T22:08:11-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579027-publish-sqlite-data-to-pdf-using-named-tuples/ <p style="color: grey"> Python recipe 579027 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/sql/">sql</a>, <a href="/recipes/tags/sqlite/">sqlite</a>, <a href="/recipes/tags/sqlite3/">sqlite3</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to publish SQLite data to PDF, using named tuples from the collections module of Python, the sqlite3 library, and the xtopdf library for PDF generation.</p> Image Converter (Python) 2015-01-18T19:14:38-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/579007-image-converter/ <p style="color: grey"> Python recipe 579007 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/conversions/">conversions</a>, <a href="/recipes/tags/convert/">convert</a>, <a href="/recipes/tags/converter/">converter</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/pil/">pil</a>). </p> <p>Converts an image from one format to another using PIL.</p> Spread sheet style column enumeration letter to number (Python) 2014-09-20T18:45:09-07:00Tomas Nordinhttp://code.activestate.com/recipes/users/4189558/http://code.activestate.com/recipes/578941-spread-sheet-style-column-enumeration-letter-to-nu/ <p style="color: grey"> Python recipe 578941 by <a href="/recipes/users/4189558/">Tomas Nordin</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/excel/">excel</a>, <a href="/recipes/tags/libreoffice/">libreoffice</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/spreadsheet/">spreadsheet</a>). </p> <p>A post-it suggestion on how to convert "Excel style" notation of columns to a number.</p> Determine bytes needed to hold integer (Python3) (Python) 2013-11-03T18:35:18-08:00teddy_khttp://code.activestate.com/recipes/users/4187115/http://code.activestate.com/recipes/578766-determine-bytes-needed-to-hold-integer-python3/ <p style="color: grey"> Python recipe 578766 by <a href="/recipes/users/4187115/">teddy_k</a> (<a href="/recipes/tags/bytes/">bytes</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/integer/">integer</a>). </p> <p>Convenience function to determine the number of bytes needed for a specified integer (split into multiple lines for clarity's sake ... could just as easily be a one-liner).</p> <p>If this is already a defined function within Python, please let me know--a quick web search turned up nothing.</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> Base Expansion/Conversion Algorithm Python (Python) 2011-11-21T19:58:14-08:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/577939-base-expansionconversion-algorithm-python/ <p style="color: grey"> Python recipe 577939 by <a href="/recipes/users/4179768/">Alexander James Wallar</a> (<a href="/recipes/tags/base/">base</a>, <a href="/recipes/tags/base16/">base16</a>, <a href="/recipes/tags/base2/">base2</a>, <a href="/recipes/tags/base_conversion/">base_conversion</a>, <a href="/recipes/tags/base_expansion/">base_expansion</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/lists/">lists</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/number_theory/">number_theory</a>, <a href="/recipes/tags/python/">python</a>). Revision 3. </p> <p>This algorithm converts a base c number into a base b number. Parameters c and b are arbitrary are not constrained by any bounds. The input n is a list and the output is a list.</p> Populate SQL tables from CSV data files (Python) 2011-02-02T21:21:49-08:00James Millshttp://code.activestate.com/recipes/users/4167757/http://code.activestate.com/recipes/577559-populate-sql-tables-from-csv-data-files/ <p style="color: grey"> Python recipe 577559 by <a href="/recipes/users/4167757/">James Mills</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sql/">sql</a>). </p> <p>Just a quick recipe I developed a few years ago that I thought might be useful to others. Basically it takes as input a data file with comma separated values (CSV) and translates this into a series of SQL "INSERT" statements allowing you to then feed this into MySQL, SQLite, or any other database.</p> <p>Example Usage:</p> <p>$ cat cars.csv Year,Make,Model,Length 1997,Ford,E350,2.34 2000,Mercury,Cougar,2.38</p> <p>$ sqlite3 cars.db "CREATE TABLE cars (Year, Make, Model, Length)"</p> <p>$ ./csv2sql.py cars.csv | sqlite3 cars.db </p> <p>$ sqlite3 cars.db "SELECT * FROM cars" 1997|Ford|E350|2.34 2000|Mercury|Cougar|2.38</p> <p>Enjoy! Feedback welcome!</p> <p>cheers James Mills / prologic</p> Convert a transcript with Ansi escape sequences to HTML (Python) 2010-10-09T22:29:42-07:00Muhammad Alkarourihttp://code.activestate.com/recipes/users/4049383/http://code.activestate.com/recipes/577349-convert-a-transcript-with-ansi-escape-sequences-to/ <p style="color: grey"> Python recipe 577349 by <a href="/recipes/users/4049383/">Muhammad Alkarouri</a> (<a href="/recipes/tags/ansi/">ansi</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/text/">text</a>). Revision 2. </p> <p>This is a stab at converting a transcript generated by the Unix <code>script</code> command that uses ANSI escape sequences, used to colour the terminal, to HTML.</p> Rename non-ASCII filenames to readable ASCII, i.e. replace accented characters, etc (Python) 2011-11-03T17:50:55-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/577226-rename-non-ascii-filenames-to-readable-ascii-ie-re/ <p style="color: grey"> Python recipe 577226 by <a href="/recipes/users/4170754/">ccpizza</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/renaming/">renaming</a>, <a href="/recipes/tags/unicode/">unicode</a>). Revision 3. </p> <p>The script converts any accented characters in filenames to their ASCII equivalents. e.g.:</p> <p>Example:</p> <pre class="prettyprint"><code>â &gt; a ä &gt; a à &gt; a á &gt; a é &gt; e í &gt; i ó &gt; o ú &gt; u ñ &gt; n ü &gt; u ... </code></pre> <p>Before-and-after example:</p> <pre class="prettyprint"><code>01_Antonín_Dvořák_Allegro.mp3 &gt;&gt;&gt; 01_Antonin_Dvorak_Allegro.mp3 </code></pre> <p>Usage:</p> <pre class="prettyprint"><code>Running the script without arguments will rename all files in the current folder. !!!WARNING!!! ***No*** backups are created. </code></pre> Python RGB and HSV Conversion (Python) 2009-10-01T06:33:56-07:00Michael Foglemanhttp://code.activestate.com/recipes/users/4171845/http://code.activestate.com/recipes/576919-python-rgb-and-hsv-conversion/ <p style="color: grey"> Python recipe 576919 by <a href="/recipes/users/4171845/">Michael Fogleman</a> (<a href="/recipes/tags/color/">color</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/convert/">convert</a>, <a href="/recipes/tags/hsv/">hsv</a>, <a href="/recipes/tags/rgb/">rgb</a>). </p> <p>Python code to convert RGB to HSV and vice-versa.</p> Convert Byte Size to String Representation (Python) 2012-04-13T19:55:07-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/576924-convert-byte-size-to-string-representation/ <p style="color: grey"> Python recipe 576924 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/representation/">representation</a>). Revision 4. </p> <p>In anticipation of creating large data structure, it appeared to be helpful if the users could get an idea of how much memory (RAM in particular) would be used while attempting to create a large, multidimensional array. In order to convert the calculated size into a precise, human-readable format, the follow code was devised. In order to convert a number into an equivalent representation of bytes, just call the "convert" function while providing the number as its argument. The other functions are currently public in case anyone else finds them useful.</p> a64l (Python) 2009-03-01T18:40:12-08:00Christoph Devenogeshttp://code.activestate.com/recipes/users/4040281/http://code.activestate.com/recipes/576578-a64l/ <p style="color: grey"> Python recipe 576578 by <a href="/recipes/users/4040281/">Christoph Devenoges</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/radix64/">radix64</a>). Revision 2. </p> <p>An implementation of a64l as from the c stdlib. Convert between a radix-64 ASCII string and a 32-bit integer.</p> Base Conversion decimal to base = len(map) (Python) 2008-08-20T05:01:39-07:00Mark Zitnikhttp://code.activestate.com/recipes/users/4166559/http://code.activestate.com/recipes/576435-base-conversion-decimal-to-base-lenmap/ <p style="color: grey"> Python recipe 576435 by <a href="/recipes/users/4166559/">Mark Zitnik</a> (<a href="/recipes/tags/base/">base</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/sequence/">sequence</a>, <a href="/recipes/tags/web_site/">web_site</a>). Revision 7. </p> <p>This code enable decimal base conversion according map length and a different char set.</p> <p>Example:</p> <ul> <li>map = ['0','1'] base 2 10 -> 1010</li> <li>map = ['a','b'] base 2 10 -> baba</li> <li>map = ['a','b','c','d','e','f','g','h','i','j','k','l'] base 12 10 -> k</li> <li>map = ['a','b','c','d','e','f','g','h','i','j','k','l'] base 12 100 -> ie</li> </ul> <p>this simple method can be used in web sites to hide a well known decimal sequence like user ids.</p>