Popular recipes by paul cannon http://code.activestate.com/recipes/users/2551140/2005-09-02T18:40:43-07:00ActiveState Code Recipesget the IP address associated with a network interface (linux only) (Python) 2005-08-11T13:30:18-07:00paul cannonhttp://code.activestate.com/recipes/users/2551140/http://code.activestate.com/recipes/439094-get-the-ip-address-associated-with-a-network-inter/ <p style="color: grey"> Python recipe 439094 by <a href="/recipes/users/2551140/">paul cannon</a> (<a href="/recipes/tags/network/">network</a>). </p> <p>Uses the Linux SIOCGIFADDR ioctl to find the IP address associated with a network interface, given the name of that interface, e.g. "eth0". The address is returned as a string containing a dotted quad.</p> get names of all "up" network interfaces (linux only) (Python) 2005-08-11T13:17:36-07:00paul cannonhttp://code.activestate.com/recipes/users/2551140/http://code.activestate.com/recipes/439093-get-names-of-all-up-network-interfaces-linux-only/ <p style="color: grey"> Python recipe 439093 by <a href="/recipes/users/2551140/">paul cannon</a> (<a href="/recipes/tags/network/">network</a>). </p> <p>Uses the SIOCGIFCONF ioctl to obtain a list of interfaces and extracts those names, returning them in a list of strings.</p> Iterator to return items N-at-a-time (Python) 2005-08-11T13:56:52-07:00paul cannonhttp://code.activestate.com/recipes/users/2551140/http://code.activestate.com/recipes/439095-iterator-to-return-items-n-at-a-time/ <p style="color: grey"> Python recipe 439095 by <a href="/recipes/users/2551140/">paul cannon</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>Creates an iterator which returns N-tuples built from the incoming items from another iterator. Useful, for example, when you need items two at a time.</p> Get the value of a cell from a closure (Python) 2005-08-11T14:46:42-07:00paul cannonhttp://code.activestate.com/recipes/users/2551140/http://code.activestate.com/recipes/439096-get-the-value-of-a-cell-from-a-closure/ <p style="color: grey"> Python recipe 439096 by <a href="/recipes/users/2551140/">paul cannon</a> (<a href="/recipes/tags/debugging/">debugging</a>). </p> <p>Python closures hold closed-over values in a special datatype called a "cell"; a sort of indirect pointer. It's not simple, though, to see what values are stored there. Here's the key.</p> Changing a closed-over value (in a "cell") (Python) 2005-09-02T18:40:43-07:00paul cannonhttp://code.activestate.com/recipes/users/2551140/http://code.activestate.com/recipes/440515-changing-a-closed-over-value-in-a-cell/ <p style="color: grey"> Python recipe 440515 by <a href="/recipes/users/2551140/">paul cannon</a> (<a href="/recipes/tags/debugging/">debugging</a>). </p> <p>In most languages with closures, it is possible to change a closed-over value and have the change visible in other closures which share a reference to the same variable. Python's syntax makes this impossible.</p> <p>Even if you're content (I am) with the work-around-- putting your changeable values inside a mutable object like a list-- it may occasionally happen that you wish you could change the closed-over values, found in "cell" objects in a function's func_closure tuple. Another recipe I submitted shows how to get at the values in standard Python; this one will demonstrate a way to actually change that value, so that functions which also close over that value (share a reference to the same cell) will see the change.</p>