@anonymous/

FrostyHiddenXiphiasgladius

Python 2.7

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class MetaConst(type):
    def __getattr__(cls, key):
        return cls[key]

    def __setattr__(cls, key, value):
        raise TypeError

class Const(object):
    __metaclass__ = MetaConst

    def __getattr__(self, name):
        return self[name]

    def __setattr__(self, name, value):
        raise TypeError

class MyConst(Const):
    A = 1
    B = 2

print MyConst.A

try:
    MyConst.A = 'changed'
except:
    print 'oops (cls)'

my_const = MyConst()

print my_const.A

try:
    my_const.A = 'changed'
except:
    print 'oops (instance)'