我正在尝试使用 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/