Skip to content

Instantly share code, notes, and snippets.

@rbpasker
Last active December 14, 2015 15:28
Show Gist options
  • Save rbpasker/5107740 to your computer and use it in GitHub Desktop.
Save rbpasker/5107740 to your computer and use it in GitHub Desktop.
cat Worker.py
class Worker(object):
def work(self):
pass
(tengahdb)rbp-imac-3:tengahdb rbp$ python
Python 2.7.2 (default, Jun 16 2012, 12:38:40)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> module = __import__("Worker")
>>> print module, dir(module)
<module 'Worker' from 'Worker.py'> ['Worker', '__builtins__', '__doc__', '__file__', '__name__', '__package__']
>>> w = getattr(module, "Worker")
>>> w.work()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unbound method work() must be called with Worker instance as first argument (got nothing instead)
>>> w.Worker()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'Worker' has no attribute 'Worker'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment