在使用 VS Code 之后,我是 Spyder 的新手,现在想要打开我的 Django 项目文件夹。我正在执行以下步骤:
Projects > New project > Existing directory > Create
但Spyder会打开一些temp.py
关闭后打开的untitled0.py
,untitled1.py
,untitled2.py
等等。如何查看我的项目结构、文件(如 VS Code 中一样)?
我已经开始将SOLID 原则应用到我的项目中。所有这些对我来说都很清楚,除了依赖倒置,因为在 Python 中,我们没有改变在另一个类中定义某个类的类型的变量(或者可能只是我不知道)。所以我以两种形式实现了依赖倒置原则,想知道哪一种是正确的,我该如何纠正它们。这是我的代码:
d1.py
:
class IFood:
def bake(self, isTendir: bool): pass
class Production:
def __init__(self):
self.food = IFood()
def produce(self):
self.food.bake(True)
class Bread(IFood):
def bake(self, isTendir:bool):
print("Bread was baked")
Run Code Online (Sandbox Code Playgroud)
d2.py
:
from abc import ABC, abstractmethod
class Food(ABC):
@abstractmethod
def bake(self, isTendir): pass
class Production():
def __init__(self):
self.bread = Bread()
def produce(self):
self.bread.bake(True)
class Bread(Food):
def bake(self, isTendir:bool):
print("Bread was baked")
Run Code Online (Sandbox Code Playgroud)