python - Cannot download Wordnet Error -


i trying compile code:

from collections import ordereddict import pdb pdb.set_trace() def alphadict(words):     alphas = ordereddict()     words = sorted(words, key = str.lower)     words = filter(none, words);     word in words:         if word[0].upper() not in alphas:             alphas[word[0].upper()] = []             alphas[word[0].upper()].append(word.lower())     return alphas  def listconvert(passage):     alphabets = " abcdefghijklmnopqrstuvwxyz"     char in passage:         if char.lower() not in alphabets:             passage = passage.replace(char, "")             listconvert(passage)     passage =  rdup(passage.split(" "))     return passage     def rdup(sequence):     unique = []     [unique.append(item) item in sequence if item not in unique]     return unique    def otherprint(word):     base = "http://dictionary.reference.com/browse/"     end = "?s=t"     nltk.corpus import wordnet wn     data = [s.definition() s in wn.synsets(word)]     print("<li>")     print("<a href = '" +base+word+end+"' target = '_blank'><h2 class = 'dictlink'>" +(word.lower())+":</h2></a>")      if not data:         print("sorry, not find word in our data banks. please click word check <a target = '_blank' class = 'dictlink' href = 'http://www.dictionary.com'>dictionary.com</a>")         return     print("<ul>")     key in data:     print("<li>"+key+"</li>")     print("</ul>")     print("</ol>")     print("</li>")     def formatprint(word):     base = "http://dictionary.reference.com/browse/"     end = "?s=t"      pydictionary import pydictionary     pd = pydictionary()     data = pd.meaning(word)      print "<li>"     print "<a href = '" +base+word+end+"' target = '_blank'><h2 class = 'dictlink'>" +(word.lower())+":</h2></a>"       if not data:     print "sorry, not find word in our data banks. please click word check <a target = '_blank' class = 'dictlink' href = 'http://www.dictionary.com'>dictionary.com</a>"     return     print "<ol type = 'a'>"     key in data:     print "<li><h3 style = 'color: red;' id = '" +word.lower()+ "'>"+key+"</h3><ul type = 'square'>"     item in data[key]:             print "<li>" +item+"</li>"     print "</ul>"     print "</li>"     print "</ol>"     print "</li>"     def specprint(words):     print "<ol>"     word in words:         otherprint(word)     print "</ol>"     print "<br/>"     print "<br/>"     print "<a href = '#list'> click here</a> go choose letter<br/>"     print "<a href = '#sentence'>click here</a> view sentence.<br/>"     print "<a href = '#header'>click here</a> see owner's information.<br/>"     print "<a href = '../html/main.html'>click here</a> go main page."     print "</div>"     x in range(0, 10):         print "<br/>" 

to answered previous question, thank you. worked, accepting answer soon. however, have problem. when try import wordnet in shell (by compiling , idle commands), process works fine. however, on xampp, error: enter image description here

can please explain well? thanks!

your loop not indented in other loop -

for key in data: print("<li>"+key+"</li>") print("</ul>") print("</ol>") print("</li>") 

this issue. try indenting it-

for key in data:     print("<li>"+key+"</li>")     print("</ul>")     print("</ol>")     print("</li>") 

also, please understand python treats tabs , spaces differently, assuming indent 1 line using tab , next line using 4 spaces (manual spaces) cause indentation error in python. have either use spaces or tabs , cannot use mixture of both (even though same).


Comments