Popular recipes tagged "meta:loc=141"http://code.activestate.com/recipes/tags/meta:loc=141/2017-02-06T18:30:18-08:00ActiveState Code RecipesLong processing computation in Tkinter or long-running task (Python) 2017-02-06T18:30:18-08:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580754-long-processing-computation-in-tkinter-or-long-run/ <p style="color: grey"> Python recipe 580754 by <a href="/recipes/users/4189907/">Miguel Martínez López</a> (<a href="/recipes/tags/computation/">computation</a>, <a href="/recipes/tags/intensive/">intensive</a>, <a href="/recipes/tags/long/">long</a>, <a href="/recipes/tags/task/">task</a>, <a href="/recipes/tags/tkinter/">tkinter</a>). Revision 12. </p> <p>I provide in this module the function "tk_call_async": It executes a function asynchronously.</p> <pre class="prettyprint"><code>tk_call_async(window, computation, args=(), kwargs={}, callback=None, polling=100, method=MULTIPROCESSING) </code></pre> <p>"tk_call_async" executes the function "computation" asynchronously with the provided "args" and "kwargs" without blocking the tkinter event loop.</p> <p>If "callback" is provided, it will be called with the result when the computation is finished.</p> <p>If an exception happens doing the computation, the errback function is called with the exception if this is provided.</p> <p>"Polling" will be the frequency to poll to check for results.</p> <p>There is two methods to execute the task: using multiprocessing or using threads.</p> Add function to Python's __builtin__ module through C API (C) 2015-10-16T12:11:58-07:00airweenhttp://code.activestate.com/recipes/users/4192997/http://code.activestate.com/recipes/579110-add-function-to-pythons-__builtin__-module-through/ <p style="color: grey"> C recipe 579110 by <a href="/recipes/users/4192997/">airween</a> (<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/builtins/">builtins</a>, <a href="/recipes/tags/c/">c</a>, <a href="/recipes/tags/exten/">exten</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>Add function to __builtin__ module through C API</p> <p>Sometimes it need to embedding a Python script to a C code, and it references to a function, which also provided by the same C code. Then you have to import the module, as you defined in your C code.</p> <p>But this import would be skipped, if you add your function to your __builtin__ module. In Python3 (3.5), there is the PyModule_AddFunctions() function, but in the previous versions, you can make it like this snippet.</p> <p>See these recipes:</p> <p>Makefile: <a href="https://code.activestate.com/recipes/579111-add-function-to-__builtin__-module-through-c-api-c/" rel="nofollow">https://code.activestate.com/recipes/579111-add-function-to-__builtin__-module-through-c-api-c/</a></p> <p>Python script: <a href="https://code.activestate.com/recipes/579112-add-function-to-__builtin__-module-through-c-api-c/" rel="nofollow">https://code.activestate.com/recipes/579112-add-function-to-__builtin__-module-through-c-api-c/</a></p> Connect 4 (DEMO) (Python) 2014-12-27T23:20:13-08:00Malcolm Jeremy Lewishttp://code.activestate.com/recipes/users/4191332/http://code.activestate.com/recipes/578995-connect-4-demo/ <p style="color: grey"> Python recipe 578995 by <a href="/recipes/users/4191332/">Malcolm Jeremy Lewis</a> . </p> <p>Connect 4 demo I created. But since it's not finished, the script does not check for diagonals but does check columns and rows. Also I am currently working on AI, but in the meantime the computer player does not have artificial intelligence</p> Manage hashes in database files. (Python) 2012-03-20T01:08:15-07:00cathy parkhttp://code.activestate.com/recipes/users/4181365/http://code.activestate.com/recipes/578083-manage-hashes-in-database-files/ <p style="color: grey"> Python recipe 578083 by <a href="/recipes/users/4181365/">cathy park</a> (<a href="/recipes/tags/caching/">caching</a>, <a href="/recipes/tags/hashes/">hashes</a>). </p> <p>This module can be used to calculate file hashes, store them in a database file and retrieve them at a later date.</p> <p>It uses the files modify time stamp to know if it can use the hash stored in the db or if it has to re-calculate it. So the user will not have to worry about the hash being incorrect if the file changes in between runs.</p> palette similar GLADE palette by pygtk (Python) 2009-01-13T22:36:23-08:00mohsen javidhttp://code.activestate.com/recipes/users/4168857/http://code.activestate.com/recipes/576614-palette-similar-glade-palette-by-pygtk/ <p style="color: grey"> Python recipe 576614 by <a href="/recipes/users/4168857/">mohsen javid</a> . Revision 3. </p> <p>this program make a palette for your items.</p> Listing the package/patches dependencies of a binary on Solaris (Python) 2008-07-30T04:30:44-07:00Benjamin Sergeanthttp://code.activestate.com/recipes/users/4039626/http://code.activestate.com/recipes/576397-listing-the-packagepatches-dependencies-of-a-binar/ <p style="color: grey"> Python recipe 576397 by <a href="/recipes/users/4039626/">Benjamin Sergeant</a> (<a href="/recipes/tags/solaris/">solaris</a>, <a href="/recipes/tags/system/">system</a>, <a href="/recipes/tags/unix/">unix</a>). Revision 2. </p> <p>Print (1) packages used by a binary, and (2) the list of installed patches related to these packages. If you have a binary that works with Solaris 10 update N, but doesn't with Solaris 10 update N-2, run this script on both platform and it will help you to find the patches you're looking for.</p> <p>(1) is retrieved:</p> <ul> <li>By using pldd(pid) on the process you want to trace to get a list of loaded shared library </li> <li>By retrieving in the main /var/sadm/install/contents database the list of package related to these shared libraries</li> </ul> <p>(2) is retrieved by parsing the output of the showrev -p command, given as input of this script</p> Search Google scholar (Python) 2007-07-13T15:20:12-07:00Yusdi Santosohttp://code.activestate.com/recipes/users/4068334/http://code.activestate.com/recipes/523047-search-google-scholar/ <p style="color: grey"> Python recipe 523047 by <a href="/recipes/users/4068334/">Yusdi Santoso</a> . </p> <p>This code allows you to search Google scholar from Python code. The result is returned in a nice dictionary format with each field addressed by its key.</p> foreach.py - Execute a python function for a selected set of files. (Python) 2004-08-19T17:12:33-07:00lonetwinhttp://code.activestate.com/recipes/users/1951998/http://code.activestate.com/recipes/300411-foreachpy-execute-a-python-function-for-a-selected/ <p style="color: grey"> Python recipe 300411 by <a href="/recipes/users/1951998/">lonetwin</a> . Revision 3. </p> <p>equivalent to doing $ find -name "*ext" -exec (some python function) {} ';'</p> portalocker - Cross-platform (posix/nt) API for flock-style file locking. (Python) 2008-05-16T21:12:08-07:00Jonathan Feinberghttp://code.activestate.com/recipes/users/1511/http://code.activestate.com/recipes/65203-portalocker-cross-platform-posixnt-api-for-flock-s/ <p style="color: grey"> Python recipe 65203 by <a href="/recipes/users/1511/">Jonathan Feinberg</a> (<a href="/recipes/tags/files/">files</a>). Revision 7. </p> <p>Synopsis:</p> <p>import portalocker file = open("somefile", "r+") portalocker.lock(file, portalocker.LOCK_EX) file.seek(12) file.write("foo") file.close()</p> HOW TO DEBUG PYTHON EXTENSIONS ON WINDOWS WITH OPEN SOURCE TOOLS (Python) 2001-10-19T22:08:20-07:00Chui Teyhttp://code.activestate.com/recipes/users/98139/http://code.activestate.com/recipes/82826-how-to-debug-python-extensions-on-windows-with-ope/ <p style="color: grey"> Python recipe 82826 by <a href="/recipes/users/98139/">Chui Tey</a> (<a href="/recipes/tags/debugging/">debugging</a>). </p> <p>I've decided to sum up my recent experiences on this issue in a short HOWTO document. There are still things that are unclear to me, like how to set breakpoints. If something doesn't work or is unclear, please point it out.</p>