一、举例
class Student:
id
name
birthdate
gender
address
phone
email
grade
vclass
major
college
二、成员list
1、使用__dir__功能
student = Student()
print(student.__dir__)
print(student.__dir__.keys())
print(student.__dir__.values())
2、使用vars()函数
student = Student()
print(vars(student))
3、使用getmembers()函数
import inspect
student = Student()
print(inspect.getmembers(student))
for i in inspect.getmembers(student):
if not i[0].startswith('_'):
if not inspect.ismethod(i[1]):
print(i)
4、列表推导式
import inspect
student = Student()
print([i for i in inspect.getmembers(student) if not i[0].startswith('_') and not inspect.ismethod(i[1])])
5、直接转数组
student = Student()
print([student])
标签:Student,Python,成员,inspect,list,student,getmembers,print,dir
From: https://www.cnblogs.com/meidanlong/p/17912959.html