Search code examples
pythonpython-module

Python - passing global variable as an argument to imported module


In order to run a program playlist.py, I have a script for a simple test interface, interface.py, with the following code:

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 is located at the same directory as interface.py, and I import the former at this point:

if __name__ == "__main__":
    from playlist import *

In playlist.py I have my classes defined, and the argument seeds should be passed like so:

playlilst.__init__(self, **seeds)

but when I run interface.py, I get the following error:

playlist.__init__(self, **seeds) NameError: global name 'seeds' is not defined

Is playlist.py being imported the right way? what am I doing wrong here?


Solution

  • In playlist.py,

    from interface import seeds