Popular Python recipes tagged "meta:requires=codecs"http://code.activestate.com/recipes/langs/python/tags/meta:requires=codecs/2017-06-13T18:44:58-07:00ActiveState Code RecipesSnake the game (Python) 2015-01-03T02:04:02-08:00Burak Tandoganhttp://code.activestate.com/recipes/users/4191373/http://code.activestate.com/recipes/578996-snake-the-game/ <p style="color: grey"> Python recipe 578996 by <a href="/recipes/users/4191373/">Burak Tandogan</a> (<a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/pygame/">pygame</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/snake/">snake</a>, <a href="/recipes/tags/the/">the</a>). Revision 3. </p> <p>Popular Snake game with Python-Pygame module. <strong>Important:</strong> If you try to run this script without special <strong>png-wav</strong> files it will fail, you have to put following files to a directory with this script. "apple.png","snakehead.png","intro.wav","dead.wav". They are basically apple picture, head of snake, intro sound and dead sound.Without them script will not run. Just make inactive the statements intro.wav and dead.wav, and find a little apple picture and snake head :).Or you can play the game just install it. <strong>Here is the installer:</strong> <a href="http://dosya.co/7c6f15c0f4d04514/Flafel-1.26-win32.rar" rel="nofollow">http://dosya.co/7c6f15c0f4d04514/Flafel-1.26-win32.rar</a> It will install the game in program files, you can find it in search "Flafel" and click to Flafel.exe. </p> Robust Testing of Tkinter Menu Items with Mocking. (Python) 2017-06-13T18:44:58-07:00Stephen Rigdenhttp://code.activestate.com/recipes/users/4191139/http://code.activestate.com/recipes/578964-robust-testing-of-tkinter-menu-items-with-mocking/ <p style="color: grey"> Python recipe 578964 by <a href="/recipes/users/4191139/">Stephen Rigden</a> (<a href="/recipes/tags/invoke/">invoke</a>, <a href="/recipes/tags/mainloop/">mainloop</a>, <a href="/recipes/tags/mock/">mock</a>, <a href="/recipes/tags/mocking/">mocking</a>, <a href="/recipes/tags/tk/">tk</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/unittest/">unittest</a>, <a href="/recipes/tags/unittesting/">unittesting</a>, <a href="/recipes/tags/unittests/">unittests</a>). Revision 7. </p> <p>This recipe addresses the problems encountered when building robust tests for Tk menus. The software under test is a simple window with two menu items that each invoke a one button dialog box. All user visible text is imported from an external config.ini file. This scenario can lead to fragile test code because of the way TK's invoke(index) command has been implemented. (Tcl8.6.3/Tk8.6.3.)</p> Ghoster - Windows program to create 0kb clone of folder or drive (Python) 2012-09-02T13:30:29-07:00commentator8http://code.activestate.com/recipes/users/4182761/http://code.activestate.com/recipes/578251-ghoster-windows-program-to-create-0kb-clone-of-fol/ <p style="color: grey"> Python recipe 578251 by <a href="/recipes/users/4182761/">commentator8</a> (<a href="/recipes/tags/clone/">clone</a>, <a href="/recipes/tags/copy/">copy</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>A program that will create a "ghost" of a given directory or drive on windows systems (easily adaptable to unix etc) to a given destination. This will consist of a copy of all folders and files with only names and extensions retained, not size. This allows browsing of a remote drive or network location when offline.</p> Correctly reading CSV files in arbitrary encodings (Python) 2011-07-25T07:29:08-07:00Devin Jeanpierrehttp://code.activestate.com/recipes/users/4178508/http://code.activestate.com/recipes/577778-correctly-reading-csv-files-in-arbitrary-encodings/ <p style="color: grey"> Python recipe 577778 by <a href="/recipes/users/4178508/">Devin Jeanpierre</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/unicode/">unicode</a>). Revision 4. </p> <p>Recipe for using unicode files (i.e. files opened with <code>codecs.open</code>) with the csv module.</p> working with GroupWise (Python) 2010-09-28T15:11:15-07:00Shamil Bikineyevhttp://code.activestate.com/recipes/users/4173185/http://code.activestate.com/recipes/577410-working-with-groupwise/ <p style="color: grey"> Python recipe 577410 by <a href="/recipes/users/4173185/">Shamil Bikineyev</a> . </p> <p>some utilities for working with <a href="http://developer.novell.com/wiki/index.php/GroupWise_Object_API">GroupWise</a> through COM-interface</p> Create book index. (Python) 2010-04-07T22:20:21-07:00Joseph Reaglehttp://code.activestate.com/recipes/users/4171494/http://code.activestate.com/recipes/577179-create-book-index/ <p style="color: grey"> Python recipe 577179 by <a href="/recipes/users/4171494/">Joseph Reagle</a> (<a href="/recipes/tags/book/">book</a>, <a href="/recipes/tags/index/">index</a>, <a href="/recipes/tags/python/">python</a>). Revision 3. </p> <p>Reads a simple enumeration of "topic (page#|see) subtopic" to create a formatted book index. </p> write_path and load_path methods for file generation scripts (Python) 2010-07-27T06:45:51-07:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/577172-write_path-and-load_path-methods-for-file-generati/ <p style="color: grey"> Python recipe 577172 by <a href="/recipes/users/4173505/">Trent Mick</a> (<a href="/recipes/tags/files/">files</a>). Revision 7. </p> <p>I have a lot of scripts that end up writing files (often build system stuff). Everytime I either end up writing the obvious quick <code>content = open(path).read()</code> or I re-implement a function that handles things like: making a backup, some typical logging, encoding support, trying to make it no-op if no changes, etc.</p> <p>In this recipe I'll try to add a number of these features so I don't have to keep re-writing this. :) So far this is just a start.</p> <p>Current features:</p> <ul> <li>rudimentary <code>encoding</code> support</li> <li>logging on a given <code>log</code> argument</li> <li><code>create_backup</code> argument to create a backup file</li> <li>writes to a temporary file and uses atomic <code>os.rename</code> to avoid destroying the existing file if writing fails</li> </ul> CMS page range validator. (Python) 2009-08-21T11:14:13-07:00Joseph Reaglehttp://code.activestate.com/recipes/users/4171494/http://code.activestate.com/recipes/576889-cms-page-range-validator/ <p style="color: grey"> Python recipe 576889 by <a href="/recipes/users/4171494/">Joseph Reagle</a> (<a href="/recipes/tags/formatting/">formatting</a>, <a href="/recipes/tags/page_ranges/">page_ranges</a>, <a href="/recipes/tags/writing/">writing</a>). </p> <p>Specification and validator for Chicago Manual of Style page ranges.</p> bier-soup.py, a small example of BeautifulSoup (Python) 2009-07-24T05:59:43-07:00denishttp://code.activestate.com/recipes/users/4168005/http://code.activestate.com/recipes/576841-bier-souppy-a-small-example-of-beautifulsoup/ <p style="color: grey"> Python recipe 576841 by <a href="/recipes/users/4168005/">denis</a> (<a href="/recipes/tags/beautifulsoup/">beautifulsoup</a>, <a href="/recipes/tags/bier/">bier</a>). Revision 3. </p> <p>bier-soup.py reads html tables like those in <a href="http://www.bier1.de" rel="nofollow">http://www.bier1.de</a> and writes plain text files, as a small example of BeautifulSoup</p> An unofficial interface of Yahoo's Chinese segmentation. (Python) 2009-07-27T21:59:20-07:00Shao-chuan Wanghttp://code.activestate.com/recipes/users/4168519/http://code.activestate.com/recipes/576859-an-unofficial-interface-of-yahoos-chinese-segmenta/ <p style="color: grey"> Python recipe 576859 by <a href="/recipes/users/4168519/">Shao-chuan Wang</a> (<a href="/recipes/tags/chinese/">chinese</a>, <a href="/recipes/tags/segmentation/">segmentation</a>, <a href="/recipes/tags/yahoo/">yahoo</a>). </p> <p>An unofficial interface of Yahoo's Chinese segmentation.</p> <ul> <li>Before use it, you MUST specify your APPID in the code. * </li> </ul> <p>Yahoo's api documents: <a href="http://tw.developer.yahoo.com/cas/" rel="nofollow">http://tw.developer.yahoo.com/cas/</a></p> Python replacement for java.util.Properties (Python) 2010-03-15T15:03:42-07:00Adam Feuerhttp://code.activestate.com/recipes/users/4159227/http://code.activestate.com/recipes/574424-python-replacement-for-javautilproperties/ <p style="color: grey"> Python recipe 574424 by <a href="/recipes/users/4159227/">Adam Feuer</a> (<a href="/recipes/tags/files/">files</a>). </p> <p>Python replacement for java.util.Properties - handles unicode escapes</p> print statement: battle with UnicodeEncodeError (Python) 2009-02-10T07:22:46-08:00Denis Barmenkovhttp://code.activestate.com/recipes/users/57155/http://code.activestate.com/recipes/523011-print-statement-battle-with-unicodeencodeerror/ <p style="color: grey"> Python recipe 523011 by <a href="/recipes/users/57155/">Denis Barmenkov</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 5. </p> <p>I received UnicodeEncodeError when playing with various codepages in source code/files/standard streams. Sometime I receive UnicodeEncodeError when script launched via scheduler or in long running batch when parsing unpredictable [alien ;)] HTML.</p> <p>Function console() helps avoid this exceptions by converting erroneous charatcters to standard python representation.</p> <p>to do in future: make a codec-wrapper for safe using in statements like this:</p> <pre class="prettyprint"><code>sys.stdout=codecs.getwriter('cp866')(sys.stdout) </code></pre> Copy gmail.com contacts onto your mobile phone via gnokii (Python) 2007-05-23T05:51:27-07:00Scott Tsaihttp://code.activestate.com/recipes/users/2482534/http://code.activestate.com/recipes/466179-copy-gmailcom-contacts-onto-your-mobile-phone-via-/ <p style="color: grey"> Python recipe 466179 by <a href="/recipes/users/2482534/">Scott Tsai</a> (<a href="/recipes/tags/text/">text</a>). Revision 6. </p> <p>This script uses the csv module to convert <a href="http://gmail.com" rel="nofollow">gmail.com</a> contacts data to the "raw" gnokii phonbook format, which is another CSV variant, while preserving cell/home/work/fax numbers, street address, URL and notes data entries.</p> <p>gnokii (<a href="http://www.gnokii.org" rel="nofollow">www.gnokii.org</a>) is an open source program for communicating with mobile phones that runs under Windows and Linux/Unix. Note that <a href="http://gmail.com" rel="nofollow">gmail.com</a> supports exporting contacts in both Outlook and Gmail CSV formats. This script needs the Gmail format.</p> <p>Run this script with a command like: cat gmail.csv | gmail-csv-to-gnokii | gnokii --writephonebook --overwrite</p> Visualize unicode strings (Python) 2005-07-14T05:59:09-07:00Wai Yip Tunghttp://code.activestate.com/recipes/users/1899280/http://code.activestate.com/recipes/436833-visualize-unicode-strings/ <p style="color: grey"> Python recipe 436833 by <a href="/recipes/users/1899280/">Wai Yip Tung</a> (<a href="/recipes/tags/text/">text</a>). Revision 2. </p> <p>You are processing unicode strings. You want to print the string but run into UnicodeEncodeError all the time. This recipe show you some simple steps to visualize unicode strings.</p> LaTeX codec (Python) 2003-11-13T23:19:20-08:00David Eppsteinhttp://code.activestate.com/recipes/users/218935/http://code.activestate.com/recipes/252124-latex-codec/ <p style="color: grey"> Python recipe 252124 by <a href="/recipes/users/218935/">David Eppstein</a> (<a href="/recipes/tags/text/">text</a>). </p> <p>Codec for converting unicodes to LaTeX markup and vice versa.</p> Auto-detect XML encoding (Python) 2001-03-14T08:33:16-08:00Paul Prescodhttp://code.activestate.com/recipes/users/11203/http://code.activestate.com/recipes/52257-auto-detect-xml-encoding/ <p style="color: grey"> Python recipe 52257 by <a href="/recipes/users/11203/">Paul Prescod</a> (<a href="/recipes/tags/xml/">xml</a>). </p> <p>The XML specification describes the outlines of an algorithm for detecting the Unicode encoding that an XML document uses. This function will do that.</p>