Defining__init__ (2 underscores before “init”, and 2 underscores after “init”!)

Programming Foundations with Python >> Lessons >> Make Classes: Movie Website >> Defining__init__

 

Problem

I sat for 30 mins trying to figure out why I was getting this error even though my code seemed identical to the teacher’s code:

Traceback (most recent call last):
  File ".../movies/entertainment_center.py", line 11, in 
    toy_story = media.Movie("Toy Story", "story of boy who's toys come to life", "http://upload.wikimedia.org/wikipedia/en/1/13/Toy_Story.jpg", "https://www.youtube.com/watch?v=vwyZH85NQC4")
TypeError: this constructor takes no arguments

Solution

I only typed 1 underscore instead of 2 underscores within media.py line 2:

Not Passing Code

class Movie():
    def _init_(self, movie_title, movie_storyline, poster_image,
               trailer_youtube):
        self.title = movie_title
        self.storyline = movie_storyline
        self.poster_image_url = poster_image
        self.trailer_youtube_url = trailer_youtube

Passing Code

class Movie():
    def __init__(self, movie_title, movie_storyline, poster_image,
               trailer_youtube):
        self.title = movie_title
        self.storyline = movie_storyline
        self.poster_image_url = poster_image
        self.trailer_youtube_url = trailer_youtube

Note: I replaced my personal filenames and directory name with “…” within line 2. Yours should be long and include your computer’s unique folder names and directory name.

File “…/movies/entertainment_center.py”

Advertisements

Author: ajoannaproject

Studying Udacity's Full Stack Web Developer program and passing on my improvements, hints, hacks, and updates to other students via ajoannaproject.wordpress.com.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s