This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: def sum(x, y): | |
...: return x+y | |
...: | |
In [2]: f = lambda n: sum(n,1) | |
In [3]: f(1) | |
Out[3]: 2 | |
In [4]: f(3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: def sum(x,y): | |
...: return x+y | |
...: | |
In [2]: increment = 1 | |
In [3]: f = lambda n: sum(n,increment) | |
In [4]: f(1) | |
Out[4]: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: def sum(x,y): | |
...: return x+y | |
...: | |
In [2]: increment = 1 | |
In [3]: f = lambda n,j=increment: sum(n,j) | |
In [4]: f(1) | |
Out[4]: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: from functools import partial | |
In [2]: def sum(x,y): | |
...: return x+y | |
...: | |
In [3]: increment = 1 | |
In [4]: f = pa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Find all Python files containing 'account' | |
; With grep: | |
saul@saghul-agp:~/work/src/python-sipsimple$ grep -R --include=*.py account * | |
; With ack | |
saul@saghul-agp:~/work/src/python-sipsimple$ ack --python account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script> | |
<script src="http://s.phono.com/releases/0.1/jquery.phono.js"></script> | |
</head> | |
<body> | |
<input id="call" type="button" disabled="true" value="Loading..." /> | |
<span id="status"></span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from application.python.util import Singleton | |
class PluginRegistry(object): | |
__metaclass__ = Singleton | |
def __init__(self): | |
self.plugins = [] | |
def __iter__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from application.python.util import Singleton | |
class PluginRegistry(object): | |
__metaclass__ = Singleton | |
def __init__(self): | |
self.plugins = [] | |
def __iter__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from optparse import OptionParser | |
from time import sleep | |
def do_something(): | |
while True: | |
print "I'm doing something" | |
sleep(5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def defer_to_thread(func): | |
"""Decorator to run DB queries in Twisted's thread pool""" | |
def wrapper(*args, **kw): | |
return deferToThread(func, *args, **kw) | |
return wrapper |