查询数据库所有id
在list
里的文章,加入article_list
.
article_list = []
for i in range(0, len(list)):
cur.execute('select * from articles where id = {}'.format(list[i]))
article_list.append(cur.fetchone())
怎么把上面的一句话写成一句 python 语句呢?
article_list.append(
cur.execute('select * from articles where id = {}'.format(list[i]))
for i in range(0, len(list))
)
这么写,返回article_list
是[<generator object <genexpr> at 0x10e112960>]
.似乎并没有拿到具体的值append
.
1
panda0 OP ```python
article_list = [cur.fetchone() for i in list if cur.execute('select * from articles where id = {}'.format(i[2])) or 1] ``` |