2017-02-20 3 views
0

Ich benutze Python 3 auf macOS Sierra und muss Sätze erstellen, die aus Synonymen bestimmter Wörter bestehen. Um dies zu tun, verwende ich PyDictionary.Probleme mit PyDictionary/BeautifulSoup

Allerdings, wenn ich meinen Code (unten angegeben) bekomme ich einen Fehler (Python-Interpreter) und eine Warnung (BeautifulSoup).

Ausgang:

/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

Warum in aller Welt würde es schöne Suppe in den Fehler haben? Hast du etwas nicht aufgenommen? – Elodin

+0

Ich benutze BeautifulSoup nicht selbst - aber gemäß dem Python Package Index verwendet PyDictionary es. https://pypi.python.org/pypi/PyDictionary –

Antwort

0

Ich habe genau das gefunden Ihre gleiche Frage, aber es wurde gelöst bei https://github.com/VitaliyRodnenko/geeknote/issues/305

Vielleicht versuchen Sie, dass, und ich bin sicher, dass Sie Ihre Antwort finden werden. Ich kann dir nicht direkt helfen, weil ich PyDictionary nicht mache, aber ich hoffe, du findest deine Antwort. Ich hoffe es hilft.

+0

Wenn ich mir die Antwort zuerst anhöre, habe ich nichts, was BeautifulSoup direkt in meinem Code betrifft, und ich würde den Quellcode von PyDictionary lieber nicht ändern. Gibt es eine andere Antwort, auf die du dich beziehst? –

+0

Nein. Entschuldigung. Das war das einzige, was ich finden konnte. – Elodin