Skip to content

Instantly share code, notes, and snippets.

@rizar
Last active August 29, 2015 14:07
Show Gist options
  • Save rizar/c1d16b2bf72fa5ceb3c4 to your computer and use it in GitHub Desktop.
Save rizar/c1d16b2bf72fa5ceb3c4 to your computer and use it in GitHub Desktop.
How to handle undefined parameteres without decorators
class UnDef():
pass
UNDEF = UnDef()
class Block(object):
def __getattribute__(self, name):
value = object.__getattribute__(self, name)
if value == UNDEF:
raise Exception("Not initialized!")
return value
class Linear(Block):
def __init__(self, input_dim=UNDEF):
self.input_dim = input_dim
def initialize(self):
print self.input_dim
b = Linear()
b.initialize() # raises "Not initialized" exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment