2016-12-28 3 views
0

다음은 파일의 저주 단어를 확인하는 파이썬 코드입니다. 하지만 왜 컴파일러 오류를 표시 찾을 수 없습니다 : module 'urllib' has no attribute 'urlopen'.내 코드 urlopen 함수에 어떤 문제가 있습니까?

import urllib 
def read_txt(): 
    quote = open("c:\\read.txt") #for opening the file 

    content = quote.read() #for reading content in a file 
    print(content) 
    quote.close() #for closing the file 
    check_profanity(content) 


def check_profanity(text): 
    connection = urllib.urlopen("https://www.wdylike.appspot.com/?q=" + text) 
    ouput = connection.read() 
    print(output) 
    connection.close() 
read_txt() 
+1

를 사용해야 동안

는 Python2에서

당신은 urllib2 사용해야합니까? –

답변

2

파이썬 3에서 urllib은 이제 여러 모듈을 수집하는 패키지입니다. urlopen() is now a part of urllib.request module :

from urllib.request import urlopen 

것은 그 다음을 사용 :

connection = urlopen("https://www.wdylike.appspot.com/?q=" + text) 
+0

도움을 주신 모든 분들께 감사드립니다. 온라인 소스에서 python 2.x를 확인하여 실수를했습니다. – Borris

1

음, urllib 때문에 urlopen 방법이 없습니다. 파이썬 3에서 사용중인 파이썬의 어떤 버전 urllib.request