2017-01-12 57 views
-4
try: 
    import sys 
    # For Python 3.0 and later 
    from urllib.request import urlopen 
except ImportError: 
    # Fall back to Python 2's urllib2 
    import sys 
    from urllib2 import urlopen 

def fetch_words(url): 
    html = urlopen(url) 
    print(html.read()) 
    story_words = [] 
    for line in html: 
     line_words = line.decode('utf-8').split() 
    for word in line_words: 
     story_words.append(word) 
    return story_words 


def print_items(items): 
    for item in items: 
     print(item) 


def main(): 
    url = sys.argv[1] 
    words = fetch_words(url) 
    print_items(words) 

if name == '__main__' 
    main() 
+0

您需要編輯問題的格式爲代碼。 – PrestonM

回答

0

你可能有其他錯誤,但肯定的是,name不宣,所以

if name == 'main' 

將提高你的錯誤。相反,它應該是

if __name__ == '__main__' 
+0

你可以嘗試一次這個代碼,並告訴我這是什麼錯誤 – chichu

+0

@chichu你是riddler?我是否應該將這些純文本作爲Python代碼運行,以便我能找出你得到的錯誤? –

相關問題