gpt4 book ai didi

python - 如何使用 pylast 获取最近听过的 4 首轨道?

转载 作者:行者123 更新时间:2023-12-01 01:25:38 25 4
gpt4 key购买 nike

我正在尝试使用 pylast 从 last_fm 获取我最近听过的 4 首歌曲。

到目前为止,我有这个代码,但操作系统只返回一首歌曲:

def get_recents(self, max_results):
recents = self.user.get_recent_tracks(max_results)
for song in recents:
return str(song.track)

最佳答案

return 语句将立即跳出循环,这意味着它只会执行一次。只需使用列表理解返回歌曲列表:

def get_recents(self, max_results):
recents = self.user.get_recent_tracks(max_results)
return [str(x) for x in recents[:4]]

关于python - 如何使用 pylast 获取最近听过的 4 首轨道?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53366407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com