python 运用三目判断对象中多个属性 有且非空

name = user.firstname if 'firstname' in user.__dir__() and user.firstname else user.name if 'name' in user.__dir__() and user.name else user.username
原文地址:https://www.cnblogs.com/twfb/p/10996410.html