Udacity_Python程序算例之创建类:电影网站

创建Movie类media.py:

import webbrowser
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
    def show_trailer(self):
        webbrowser.open(self.trailer_youtube_url)

创建编写“电影网站”代码fresh_tomatoes.py:

https://github.com/udacity/ud036_StarterCode/blob/master/fresh_tomatoes.py

创建电影文件entertrainment_center.py:

import media
import fresh_tomatoes
toy_story = media.Movie("Toy Story",
                        "A story of a boy and his toys that come to life",
                        "http://upload.wikimedia.org/wikipedia/en/1/13/Toy_Story.jpg",
                        "https://www.youtube.com/watch?v=vwyZH85NQC4")
#print(toy_story.storyline)
avatar = media.Movie("Avatar",
                     "A marine on an alien planet",
                     "http://upload.wikimedia.org/wikipedia/id/b/b0/Avatar-Teaser-Poster.jpg",
                     "http://www.youtube.com/watch?v=-9ceBgWV8io")
# print(avatar.storyline)
# avatar.show_trailer()
school_of_rock = media.Movie("School of Rock","Storyline",
                             "http://upload.wikimedia.org/wikipedia/en/1/11/School_of_Rock_Poster.jpg",
                             "https://www.youtube.com/watch?v=3PsUJFEBC74")

ratatouille = media.Movie("Ratatouille","Storyline",
                          "http://upload.wikimedi.org/wikipedia/en/5/50/RatatouillePoster.jpg",
                          "https://www.youtube.com/watch?v=c3sBBRxDAqk")

midnight_in_paris = media.Movie("Midnight in Paris","Storyline",
                                 "http://upload.wikimedia.org/wikipedia/en/9/9f/Midnight_in_Paris_Poster.jpg",
                                 "https://www.youtube.com/watch?v=atLg2wQQxvU")

hunger_games = media.Movie("Hunger Games","Storyline",
                           "http://upload.wikimedia.org/wikipedia/en/4/42/HungerGamersPoster.jpg",
                           "http://www.youtube.com/watch?v=PbA63a7H0bo")
movies = [toy_story,avatar,school_of_rock,ratatouille,midnight_in_paris,hunger_games]
fresh_tomatoes.open_movies_page(movies)

最终效果:

Udacity_Python程序算例之创建类:电影网站_第1张图片
电影网站
  • 注:部分海报和宣传片由于版权问题不能显示和播放

你可能感兴趣的:(Udacity_Python程序算例之创建类:电影网站)