annotate python/example/fireonce.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 dbe9086643bf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
164
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 class fireonce(object):
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 def __init__(self, func):
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 self.func = func
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 def __call__(self, *args, **kwargs):
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 if not self.func:
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 return None
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 retval = self.func(*args, **kwargs)
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 self.func = None
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 @fireonce
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 def foo(x):
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 print x
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 foo('bar')
8006938c33ac add fireonce decorator example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 foo('fleem') # not printed