вывести все данные из бд из конкретного столбца
@clan.command()
async def profile(self, ctx):
author = ctx.message.author
clan_id = cur.execute(f'SELECT ClanId FROM UserClans WHERE UserId = {author.id}').fetchone()
cur.execute(f'SELECT UserName FROM UserClans WHERE {clan_id[0]}')
users = cur.fetchall()
l = []
l.append(users)
return print(l)
Мне нужно вывести всех юзеров клана, но таким способом выводит только первого в списке. Есть ли способ вывести всех без цикла?
Ответы (1 шт):
Автор решения: alex
→ Ссылка
append() добавляет только один элемент
Для добавления множества элементов используйте extend()
@clan.command()
async def profile(self, ctx):
author = ctx.message.author
clan_id = cur.execute(f'SELECT ClanId FROM UserClans WHERE UserId = {author.id}').fetchone()
cur.execute(f'SELECT UserName FROM UserClans WHERE {clan_id[0]}')
users = cur.fetchall()
l = []
l.extend(users) # одно изменение
return print(l)