有没有一种方法可以将附加方法添加到从python中的对象类继承的类中。
这是我的问题...我有一个句子,单词和字符类...并且我希望能够将一个字符附加到感觉中...但是当我这样做时
string_a = Character('a')
string_b = Character('b')
string_c = Character('c')
str_list = [string_a, string_b, string_c]
# this part works fine
sentience = Sentence(str_list)
# this part does not work... but it makes sense why not, because I'm adding two data types to one object.
# but sense sentience inherits from character, and it's really just a list of characters... I was thinking there must be some way to append another character to it.
new_str_list = [sentience + string_a]
new_sentience = Sentence(new_str_list)
python引发了一个错误,这很有意义……但是所有这些要说的是,有一种方法可以追加到特定的实例化Sentience类(正如我之前提到的只是对象类的子类)或向其中添加字符实例化预先存在的情感对象?问题是我正在制作通过HTML的Character / word / sentience / paragraph词法标记程序...,并且我不想保持html完整,所以我正在建立这样的类结构,因为事情例如HTML标记具有自己的数据类型,因此我可以稍后再添加它们。
慕容3067478
相关分类