2017-05-31 67 views
-1

嗨,當我試圖使用這段代碼:媒體IndentationError:預計縮進塊

import media 

toy_story = media.Movie("Toy Story","A story of a boy and his toys 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) 

媒體和此文件的目錄是:C:\Users\Lukes\Desktop\media

媒體的代碼是在這裏:

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 

,每當我試圖運行entertainment_center.py

它與此出來:

Traceback (most recent call last): 
    File "C:/Users/Lukes/Desktop/media/entertainment_center.py", line 1, in <module> 
    import media 
    File "C:/Users/Lukes/Desktop/media\media.py", line 2 
    ^
IndentationError: expected an indented block 
+1

爲什麼你的'import'有一個縮進? –

回答

1

方法__init__是與類作用域。縮進來考慮這一點。

class Movie(object): 
    def __init__(self): 
     self.id = 0 

另外,不要縮進頂部import指令在第一個文件中。

相關問題