100+ almost identical classes is crazy. Classes are organizational structures. Having dozens of them with almost no variation does't seem useful. It's over-specialization.
It sounds very much like you need a single class with a shared lookup-table that defines the shared info. Something like:
from collections import namedtuple
Lang= namedtuple('Lang','style points creator')
LANG_FORM ={'Python':Lang('dynamic',84,'Guido van Rossum'),'Java':Lang('static',65,'James Gosling'),# ...'Pascal':Lang('static',33,'Niklaus Wirth')}classProtean(object):def __init__(self, name, form):
self.name = name
self.form = form
self.lang = LANG_FORM[form]# optional# methods here
Here LANG_FORM
can be a global variable (quasi-constant), or it could be a class variable. Either way, each instance gets basically just a pointer back to its shared info (what you refer to as class variables). It doesn't even strictly need that, if you're willing to index LANG_FORM
whenever you need it, rather than memorizing it in each instance.
If you want to have each of the instances depict itself based on its form/kind/quasi-class, add a __repr__
method:
def __repr__(self):
classname = self.__class__.__name__
return"{0}-{1}({2!r}, {3})".format(classname, self.form, self.name, self.lang.points)
Then:
p =Protean('CPython','Python')print p
Yields:
Protean-Python('CPython',84)
相关推荐
RevitLookup-2021.0.0.13,供各位做REVIT二次开发的同仁们下载、学习、研究。
revit开发必备工具 本包中是已经编译过的文件,可以直接使用 ...编辑其中RevitLookup.dll 路径为编译路径 C:\RevitLookup-2016.0.0.6\CS\bin\Debug\RevitLookup.dll 重启revit: 即可在菜单栏看到工具
RevitLookup-2017.0.0.5RevitLookup-2017.0.0.5RevitLookup-2017.0.0.5RevitLookup-2017.0.0.5RevitLookup-2017.0.0.5
This paper documents a detailed, industrially practical procedure of characterizing the torque lookup table for interior permanent magnet (IPM) synchronous machines. The characterized lookup table ...
基于嵌入式的正弦查表程序.在sintable.asm中定义的正弦表.系统频率设置49.152MHz,强振模式.
RevitLookup - 2016 的 源码,需要自己编译 用法:将RevitLookup.addin和RevitLookup.dll放到C:\ProgramData\Autodesk\Revit\Addins\2016下即可
RevitLookup - 2017 的 源码,需要自己编译 用法:将RevitLookup.addin和RevitLookup.dll放到C:\ProgramData\Autodesk\Revit\Addins\2017下即可
前端开源库-nsq-lookup-jcnsq lookup jc,通过nsqlookupd查找nsqd实例
RevitLookup-2020.0.0.4 官方公布源代码需要自己编译,方便学习REVIT内核构架和开发
RevitLookup - 2018 的 源码,需要自己编译 用法:将RevitLookup.addin和RevitLookup.dll放到C:\ProgramData\Autodesk\Revit\Addins\2018下即可
资源分类:Python库 所属语言:Python 使用前提:需要解压 资源全名:iso3_lookup-0.3.0-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
python库,解压后可用。 资源全名:databricks_feature_lookup-0.0.5-py3-none-any.whl
资源来自pypi官网。 资源全名:digdeo-syspass-ansible-lookup-0.2.4.tar.gz
资源来自pypi官网。 资源全名:databricks_feature_lookup-0.0.5-py3-none-any.whl
资源来自pypi官网。 资源全名:drf-multi-lookup-0.0.14.tar.gz
lookup-dns- dns.lookup替换dns.lookup标准方法的DNS缓存超级简单易用const request = require ( 'request' ) ;const { lookup } = require ( 'lookup-dns-cache' ) ;// With "request" modulerequest ( { url : '...
python库,解压后可用。 资源全名:spacy_lookup-0.0.5-py2.py3-none-any.whl
资源来自pypi官网。 资源全名:spacy_lookup-0.0.5-py2.py3-none-any.whl
资源来自pypi官网。 资源全名:django_lookup_extensions-0.2.0-py2.py3-none-any.whl
资源来自pypi官网。 资源全名:drf-multi-lookup-0.0.19.tar.gz