如何解决python方法:append在抽象类的子类中返回一个空列表
我正在尝试熟悉抽象类,但不知道如何附加到类中的空列表。这是我正在工作的目录的样子:
my_dir
|__data
| |__colors
| | |__light_colors.csv
| | |__dark_colors.csv
| | |__cold_colors.json
| |__ages
|__code
|__data_reader.py
|__config.py
在我的配置文件中:
import os
REPO_ROOT_DIRECTORY = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
colors_data_dirECTORY = os.path.join(REPO_ROOT_DIRECTORY,"data")
在我的 data_reader.py 文件中,我有以下代码,它是一个抽象类。
from abc import ABC,abstractmethod
from config import colors_data_dirECTORY
import os
class PathReader(ABC):
@abstractmethod
def read_data_type(self): pass
class colorReader(PathReader):
def __init__(self):
self.path_to_types = os.path.join(colors_data_dirECTORY,'colors')
self.colors= []
# print(self.colors)-->empty
def read_data_type(self):
for files in os.listdir(self.path_to_types):
all_colors = os.path.join(self.path_to_types,files)
self.colors.append(all_colors)
# print(all_colors) --> prints the .csv and .json files and their path
# print(files) --> prints the .csv and .json files
g= colorReader()
print(g.read_data_type())
我不确定方法的哪一部分是错误的,因此附加不起作用。我试图打印出 for 循环中的元素,一切看起来都很好,但是当我打印 self.colors 列表时,它是空的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。