refactor(files): 优化项目
- 重构files - 新增yaml_processor(优化读取文件逻辑) - 修复bug
This commit is contained in:
39
commons/file_processors/base.py
Normal file
39
commons/file_processors/base.py
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
|
||||
"""
|
||||
@author: CNWei
|
||||
@Software: PyCharm
|
||||
@contact: t6i888@163.com
|
||||
@file: base
|
||||
@date: 2025/3/4 17:23
|
||||
@desc:
|
||||
"""
|
||||
import abc
|
||||
|
||||
|
||||
class BaseFileProcessor(abc.ABC): # 使用 abc 模块定义抽象基类
|
||||
"""
|
||||
文件处理器的抽象基类。
|
||||
定义了所有子类必须实现的方法。
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def load(self):
|
||||
"""加载."""
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def to_string(self) -> str:
|
||||
"""将文件内容转换为字符串。"""
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def to_dict(self, data: str) -> dict:
|
||||
"""将文件内容转换为字典。"""
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def save(self, new_filepath=None):
|
||||
"""将数据保存."""
|
||||
pass
|
||||
Reference in New Issue
Block a user