将过程转换为面向对象:Python3.4

时间:2015-10-02 21:32:11

标签: python class oop

为了更加“pythonic”(并且更加模块化),我想将我的程序代码转换为wife。这里感兴趣的对象是lastnameyield的婚姻的概念,这里称为get_husband,在每个配偶之间有一些共享和一些独特的属性。这些属性通过get_wife从文件填充到生成器对象中。

我的一部分想要执行这两个解析函数marriage.firstnamemarriage.husbandscore(也许是最终的zip函数)作为一个仍然使用迭代器对象填充{{的属性的类函数1}},marriage.wifescoremarriage等。然后,我会创建一些方法,对每个self对象的信息进行进一步分析,因为它从生成器中吐出。

但部分我不确定解析定义是否最好保留为方法,因为我将返回from itertools import izip def get_husband(husbandfile): lastname, firstname, husbandscore = '', '', '' for line in husbandfile.readlines(): # Parse files to fill out the names, wifescores in wifefile yield name, husbandscore def get_wife(wifefile): lastname, firstname, wifescore = '', '','' for line in wifefile.readlines(): # Parse files to fill out the names, wifescores in wifefile yield name, wifescore def make_family(husbandfile, wifefile): for husband, wife in izip(get_husband(husbandfile), get_wife(wifefile)): if husband[0] == wife[0]: lastname = husband[0] parentscore = husband[1] + wife[0] yield lastname, parentscore else: raise Exception("These two aren't married ,这不是我下游工作所需的生成器......

min_score = marriage.parentscore.min()

您认为将此作为一个课程的最佳方式是什么,所以我可以这样:{{1}}

0 个答案:

没有答案