为了运行程序playlist.py
,我有一个简单测试界面的脚本interface.py
,其代码如下:
seeds = {}
user_input1 = raw_input("Please pick a seed: track, artist or genre. >> ")
user_input2 = raw_input("which one? >> ")
if user_input1 == 'track':
seeds['track'] = user_input2
elif user_input1 == 'artist':
seeds['artist']= user_input2
else:
seeds['genre'] = user_input2
playlist.py
与interface.py
位于同一目录,我此时导入前者:
if __name__ == "__main__":
from playlist import *
在playlist.py
我定义了我的类,并且应该像这样传递参数seeds
:
playlilst.__init__(self, **seeds)
但是当我运行interface.py
时,我收到以下错误:
playlist.__init__(self, **seeds)
NameError: global name 'seeds' is not defined
playlist.py
是否以正确的方式导入?我在这做错了什么?
答案 0 :(得分:0)
在playlist.py中,
from interface import seeds