adding all files done so far
This commit is contained in:
BIN
learning/singletons/__pycache__/db.cpython-37.pyc
Normal file
BIN
learning/singletons/__pycache__/db.cpython-37.pyc
Normal file
Binary file not shown.
6
learning/singletons/client_a.py
Normal file
6
learning/singletons/client_a.py
Normal file
@@ -0,0 +1,6 @@
|
||||
mygenerator = (x * x for x in range(3))
|
||||
for i in mygenerator:
|
||||
print(i)
|
||||
|
||||
for i in mygenerator:
|
||||
print(i)
|
||||
4
learning/singletons/client_b.py
Normal file
4
learning/singletons/client_b.py
Normal file
@@ -0,0 +1,4 @@
|
||||
import db
|
||||
|
||||
if (db.db_name == 'mongo'):
|
||||
db.db_name = None
|
||||
19
learning/singletons/db.py
Normal file
19
learning/singletons/db.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.getcwd()) # noqa E402
|
||||
this = sys.modules[__name__]
|
||||
|
||||
print(this)
|
||||
|
||||
this.db_name = None
|
||||
|
||||
print(this.db_name)
|
||||
|
||||
|
||||
def initialize_db(name):
|
||||
if (this.db_name is None):
|
||||
this.db_name = name
|
||||
# db_name = "Local Variable"
|
||||
else:
|
||||
msg = f"Database is already initialized to {name}"
|
||||
raise RuntimeError(msg.format(this.db_name))
|
||||
Reference in New Issue
Block a user