未明确定义名称“ sp”

时间:2019-11-13 03:35:18

标签: python python-3.x numpy machine-learning spotipy

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

有人可以帮助我吗?我尝试搜索详细文档,但显示的是我在此处使用的相同代码。

2 个答案:

答案 0 :(得分:1)

确保您输入:

sp = spotipy.Spotify()

答案 1 :(得分:0)

根据错误,尝试添加:

from spotipy import Spotify as sp

作为代码的第一行,它看起来不像您导入的spotipy