Answer the question
In order to leave comments, you need to log in
How to split a project into modules?
There are 3 files:
api.py, users.py, posts.py
All names are fictitious, but reflect the meaning of this whole task. So. The api.py file has a settings class that is updated on the user's command:
class settings:
def update(self, sql): self.settings = sql.get_settings_from_db()
settings = settings()
settings.update(sql)
class settings:
def update(self, sql): self.settings = sql.get_settings_from_db
class users:
def say_id(self):
print(settings.settings.id)
class posts:
def do(self):
print(settings.settings.posts)
#code here
settings = settings()
from classes.users import users
from classes.posts import posts
class settings:
def update(self, sql): self.settings = sql.get_settings_from_db
settings = settings()
users = users()
posts = posts()
users.say_id()
class users:
def say_id(self):
print(settings.settings.id)
class posts:
def do(self):
print(settings.settings.posts)
#code here
users.say_id(settings)
Answer the question
In order to leave comments, you need to log in
First you need to initialize the instances in the settings class.
class Settings(object):
def __init__(self):
self.posts = Posts()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question