我正在使用这个功能
def convert_tuple(self,listobj,fields=['start','end','user']):
return [(getattr(obj,field) for field in fields)
for obj in listobj]
我想要的输出应该是
[('2am','5am','john'),('3am','john1'),'john2') ]
[genexp,genexp,genexp]
它的生成器表达式,我无法像我想的那样扩展它
最佳答案
将gen-exp转换为元组
原文链接:https://www.f2er.com/python/438898.htmldef convert_tuple(self,'user']):
return [tuple(getattr(obj,field) for field in fields)
for obj in listobj]