Mercurial > hg > config
annotate python/example/bind.py @ 694:ebca6d85213a
File "/usr/lib/python3/dist-packages/IPython/config/__init__.py", line 16, in <module>
from .application import *
File "/usr/lib/python3/dist-packages/IPython/config/application.py", line 31, in <module>
from IPython.config.configurable import SingletonConfigurable
File "/usr/lib/python3/dist-packages/IPython/config/configurable.py", line 33, in <module>
from IPython.utils.text import indent, wrap_paragraphs
File "/usr/lib/python3/dist-packages/IPython/utils/text.py", line 28, in <module>
from IPython.external.path import path
File "/usr/lib/python3/dist-packages/IPython/external/path/__init__.py", line 2, in <module>
from path import *
File "/home/jhammel/python/path.py", line 25
print root(path)
^
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 09 Jul 2014 16:26:49 -0700 |
parents | 4063bbeaa7d4 |
children |
rev | line source |
---|---|
263
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 |
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 """ |
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 illlustrate e.g. method bind for python |
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 """ |
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 |
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 class Foo(object): |
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 |
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 @classmethod |
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 def create(cls): |
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 """create an instance and bind a method onto foo""" |
264 | 12 class decorator(object): |
13 def __init__(self, function): | |
14 self.function = function | |
15 def __call__(self): | |
16 print "Bar!" | |
17 return self.function() | |
18 | |
19 instance = cls() | |
20 instance.foo = decorator(instance.foo) | |
21 return instance | |
263
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
22 |
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
23 def foo(self): |
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
24 print "Foo!" |
7b15ed0b372c
add a sample to bind to an instance, stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
25 |
264 | 26 if __name__ == '__main__': |
27 foo = Foo.create() | |
28 foo.foo() |