面向对象小作业

#练一练
'''练习一:在终端输出如下信息

小明,10岁,男,上山去砍柴
小明,10岁,男,开车去东北
小明,10岁,男,最爱大保健
老李,90岁,男,上山去砍柴
老李,90岁,男,开车去东北
老李,90岁,男,最爱大保健
老张…'''
a='''小明,10岁,男,上山去砍柴
小明,10岁,男,开车去东北
小明,10岁,男,最爱大保健
老李,90岁,男,上山去砍柴
老李,90岁,男,开车去东北
老李,90岁,男,最爱大保健'''
f=open('confo.txt',mode='w',encoding='utf-8')
f.write(a)
f.close()
class mingzi:
    def __init__(self,name,age,sex,hobby):
        self.name=name
        self.age=age
        self.sex=sex
        self.hobby=hobby
    def func(self):
        print(self.name,self.age,self.sex,self.hobby,sep=',')
f=open('confo')
# d = (a for a in ['a','b','c','d','e','f'])
for  i in range(6):

    content=f.readline().strip().split('')
    # print(content)
    adc =mingzi(content[0],content[1],content[2],content[3])
    mingzi.func(adc)


f.close()
原文地址:https://www.cnblogs.com/accolade/p/10497315.html