forked from UWPCE-PythonCert/ProgrammingInPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_solution.py
More file actions
55 lines (40 loc) · 1.3 KB
/
Copy pathmy_solution.py
File metadata and controls
55 lines (40 loc) · 1.3 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# original class made as simple as possible
class TestClass(object):
engine = None
def __init__(self, config):
self.config = config
self.data = None
def initialize(self):
print('initialize data')
self.data = 'initialized'
def _get_engine(self):
if not TestClass.engine:
self.initialize()
TestClass.engine = 'on'
return TestClass.engine
def get_privilege(self):
engine = self._get_engine()
return self.data, TestClass.engine
class MyClass(object):
class __MyClass(object):
def __init__(self, db_config):
self.db_config = db_config
self.data = None
self.engine = None
def initialize(self):
print('initialize data')
self.data = 'initialized'
def _get_engine(self):
if not self.engine:
self.initialize()
self.engine = 'on'
return self.engine
def get_privilege(self):
engine = self._get_engine()
return self.data, self.engine
instance = None
def __init__(self, db_config):
if not MyClass.instance:
MyClass.instance = MyClass.__MyClass(db_config)
def __getattr__(self, name):
return getattr(self.instance, name)