Answer the question
In order to leave comments, you need to log in
Can a class implementation depend on external modules?
Good day to all!
Here I have a class. This class internally uses some object of another class.
I see two options for implementing this:
from file_b import ClassB
class A:
def __init__(self, b: ClassB):
self.__b = b
# Дальше используем уже self.__b.
from file_b import b
class A:
def __init__(self):
pass
def some_fun(self):
b.some_method_b()
Answer the question
In order to leave comments, you need to log in
That's right. It is better to pass dependencies through the constructor
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question