So I have a class like this:
class Encoder(object):
movie = None
def __init__(self, movie_instance):
self.movie = movie_instance
def encode_profile_hd(self):
print "profile 1"
def encode_profile_sd(self):
print "profile 2"
How can I specify the movie_instance argument passed to the constructor must be of Movie class?
I tried:
def __init__(self, Movie movie_instance):
But that doesn’t work. Sorry if this is obvious.
you can use
isinstancefor that.This will work for
Movieinstances as well as anything that inherits fromMovie.It’s worth noting that a lot of people would say that in Python, this idiom should not be used often. If something looks like a movie, smells like a movie (do movies have a scent?) and plays like a movie, why not just treat it like a movie? (In other words, try to use the object like a movie and handle the exception that is raised if it doesn’t work).