Python - 将全局变量作为参数传递给导入的模块

Python - passing global variable as an argument to imported module

为了运行一个程序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.pyinterface.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 的导入方式是否正确?我在这里做错了什么?

在playlist.py,

from interface import seeds