I did not know you could do this

never_seen_this_before = True

class Test():
    if never_seen_this_before:
        def some_method(self):
            print "Weird!"
    else:
        def some_other_method(self):
            print "Normal!"
>>> t=Test()
>>> t.some_method()
Weird!
>>> t.some_other_method()
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    t.some_other_method()
AttributeError: Test instance has no attribute 'some_other_method'
Advertisements