以直线显示数据并通过python很好地对齐

时间:2016-04-09 06:18:16

标签: python

现在该怎么办,请现在该做什么 如何追加感谢

students.append(s1)
students.append(s1)
students.append(s1)
students.append(s1)
students.append(s1)
students.append(s1)
students.append(s1)
students.append(s1)
students.append(s1)
students.append(s1)

2 个答案:

答案 0 :(得分:1)

您可以向学生班级添加__str__方法:

class student:
def __init__(self, code, name, number):
    self.code = code
    self.name = name
    self.number = number

def __str__(self):
    return '\t'.join((self.code, self.name, self.number))

students = []
s1 = student("901", "Joh Doe", "123456")
s2 = student("902", "Mary Mount", "566665")
s3 = student("903", "David Lee", "394624")

students.append(s1)
students.append(s2)
students.append(s3)

for student in students:
    print student

答案 1 :(得分:0)

首先安装tabulatelocalhost

pip install tabulate