我在列表中存储了一组属性,并且有一个名为customuser的对象,我希望迭代列表中的属性并显示数据库中的值
fieldx={'department','usertype','company'}
for f in fieldx:
print(customuser.f)但是我得到了以下错误信息:'CustomUser‘对象没有属性'f’你能帮我这个忙吗?谢谢
发布于 2021-03-30 06:20:11
使用内置getattr
fieldx={'department','usertype','company'}
for f in fieldx:
print(getattr(customuser, f))https://stackoverflow.com/questions/66862311
复制相似问题