Skip to content

Instantly share code, notes, and snippets.

View monkeytruffle's full-sized avatar

monkeytruffle

View GitHub Profile
@dhilst
dhilst / delegate.py
Last active January 24, 2025 19:57
Delegate methods in python
def delegate(to, *methods):
'''
Class decorator to delegate methods to another objects.
>>> @delegate('v', 'upper')
... @delegate('v', 'lower')
... @delegate('v', 'wrong_method')
... @delegate('not_an_attribute', 'wrong_attribute')
... class Foo:
... def __init__(self, v):
... self.v = v
@everilae
everilae / threadedgenerator.py
Last active January 24, 2025 19:58
Threaded generator wrapper for Python
# A simple generator wrapper, not sure if it's good for anything at all.
# With basic python threading
from threading import Thread
try:
from queue import Queue
except ImportError:
from Queue import Queue