I am trying to implement a project using
class inheritance, where parent class is:
class radio: def __init__(self, artist=None, track=None, genre=None): self.artist = artist self.track = track self.genre = genre
then I create
methods for each
attribute (non working examples):
def seed_artist(self): results = api.search(q=self.artist, type='artist') return results def seed_track(self): results = api.search(q=self.track, type='track') return results def seed_genre(self): results = api.search(q=self.genre, type='genre') return results
the user is going to pick a seed above (only one), being it either
mood, and that's why I initialize all arguments with
None, leaving the argument value to be inserted at inheritance level.
class playlist(radio): def __init__(self,user): radio.__init__(self, artist, track, genre)
lets say user inputs at command line a
track seed, and my script ends up starting with a global variable:
track = 'karma police'
this way, all other attributes (
when I create an instance, say:
jeff = playlist('Jeff Smith')
It will throw an error saying that
artist are not defined, and I would have to inherit only
trackattribute, like so:
I know I could start the script with global variables defined:
track = None genre = None artist = None
and this would allow me to have:
radio.__init__(self, artist, track, genre)
but this seems to me rather redundant...
Is there a workaround this, with no need for initial values of global variables set to
None, keeping all the code within class scope definitions?