2017-02-20 1 views
0

저는 macOS Sierra에서 Python 3을 실행 중이며 특정 단어의 동의어로 구성된 문장을 만들어야합니다. 이렇게하려면 PyDictionary를 사용하고 있습니다.PyDictionary/BeautifulSoup 문제

그러나 아래 코드에서 코드를 실행할 때 오류 (Python 인터프리터)와 경고 (BeautifulSoup)가 표시됩니다.

출력 :

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beautifulsoup4-4.5.3-py3.5.egg/bs4/__init__.py:181: UserWarning: No parser was e 
xplicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on an 
other system, or in a different virtual environment, it may use a different parser and behave differently. 

The code that caused this warning is on line 53 of the file main.py. To get rid of this warning, change code that looks like this: 

BeautifulSoup([your markup]) 

to this: 

BeautifulSoup([your markup], "html.parser") 

    markup_type=markup_type)) 
Traceback (most recent call last): 
    File "main.py", line 53, in <module> 
    edison() 
    File "main.py", line 29, in edison 
    say(respond(["I", "am", "happy", "to", "hear", "that", "html.parser"]) + "!") 
    File "/path/to/code/respond.py", line 9, in respond 
    output = (output + " " + (random.choice(dictionary.synonym(word, "html.parser")))) 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/random.py", line 265, in choice 
    return seq[i] 
KeyError: 0 

main.py :

from respond import * 


def edison(): 
    mood = input("Hi, " + username + "! How are you today? ") 
    if mood.lower() in definitions.positive: 
     print(respond(["I", "am", "happy", "to", "hear", "that", "html.parser"]) + "!") #This is line 29 
    elif mood.lower() in definitions.negative: 
     print(respond(["I", "am", "sorry", "to", "hear", "that", "html.parser"]) + "!") 



edison() #This is line 53 

respond.py :

import random 
from PyDictionary import PyDictionary 
dictionary = PyDictionary() 

def respond(wordList): 
    output = "" 
    for word in wordList: 
     output = (output + " " + (random.choice(dictionary.synonym(word, "html.parser")))) 
    return output 
+0

왜이 지구상에는 아름다운 스프가 있습니까? 뭔가를 포함시키지 않았습니까? – Elodin

+0

나 자신이 BeautifulSoup을 사용하지 않고있다. 그러나 Python Package Index PyDictionary에 의하면 그것을 사용하고있다. https://pypi.python.org/pypi/PyDictionary –

답변

0

내가 정확히 발견 동일한 질문이지만 해결되었습니다. https://github.com/VitaliyRodnenko/geeknote/issues/305

어쩌면 그 시도를 시도해보고 답변을 찾을 수있을 것입니다. 나는 PyDictionary를하지 않기 때문에 직접적으로 당신을 도울 수는 없지만 당신이 당신의 답을 찾길 바란다. 도움이되기를 바랍니다.

+0

답변을 먼저 보았을 때, 제 코드에서 BeautifulSoup을 직접 언급하지 않았으며 PyDictionary의 소스 코드를 변경하지 않을 것입니다. 당신이 말하는 또 다른 대답이 있습니까? –

+0

아니요. 죄송합니다. 이것이 내가 찾을 수있는 유일한 것입니다. – Elodin