名称“sp”的定义不明确

2024-05-01 21:55:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在与numpy和spotipy一起检索我的播放列表。这是我有问题的代码

def get_features_for_playlist(uri):
    playlist_id = uri.split(':')[2]
    results = sp.user_playlist(username, playlist_id)

它不断地给我错误

NameError: name 'sp' is not defined

有人能帮帮我吗。我试过搜索那些杂乱无章的文档,但它显示的代码与我在这里使用的代码相同。你知道吗


Tags: 代码numpyidforgetdefuri播放列表
2条回答

根据错误,尝试添加:

from spotipy import Spotify as sp

作为代码的第一行,它看起来不像您导入了spotipy。你知道吗

一定要写:

sp = spotipy.Spotify()

相关问题 更多 >