python - 静态嵌套类可以是 Python 3 中外部类的子类吗?
问题描述
我创建了一个类来存储 TF-IDF 矩阵生成的设置。
class TFIDF_settings:
max_features = 5000
class word_level(TFIDF_settings):
analyzer = "word"
ngram_range = (1,1)
class ngram_level(TFIDF_settings):
analyzer = "word"
ngram_range = (2,3)
我希望该属性TFIDF_settings.max_feature
能够顺利传递给所有内部类 -print(TFIDF_settings.word_level.max_features)
应该返回5000
。
正如您在代码中看到的那样,我认为继承外部类可以完成这项工作,但它会抛出一个NameError
.
<ipython-input-18-0ddd9158decc> in TFIDF_settings()
2 max_features = 5000
3
----> 4 class word_level(TFIDF_settings):
5 analyzer = "word"
6 ngram_range = (1,1)
NameError: name 'TFIDF_settings' is not defined
有没有办法(最好是隐式地)将max_features
外部类的属性传递给内部类?
解决方案
推荐阅读
- docker - Nginx 为 Rocket.chat 返回 504。我相信问题出在我的 nginx.config
- reactjs - 如何传入任何对象以进行自定义钩子反应
- excel - 一个更好的自动过滤表代码到另一个表 Visual basic Excel
- python - 在音频文件上对我的机器学习模型进行单元测试时出错
- python - ipywidgets Textarea on_submit()
- javascript - Javascript:当有多个记录时,要在新行中显示记录
- solidity - 创建一个新合同,但不断收到此错误此合同可能是抽象的,未实现抽象的父方法
- java - 从子类操作父类的私有变量
- c - 使用 struct 保护 ISR 中的全局变量
- python - 将 PEST++ 与代理模型耦合