2014-03-31 3 views
1

간단한 단어 가드를 만들려고합니다. urbandict.py을 Python 2.7에 설치했습니다. 이 API는 JSON 객체를 통해 데이터를 처리합니다. 단어가 도시 사전에 있다면 나는 사실을 원한다. 그렇지 않으면 거짓이다.목록 색인 범위를 벗어남 오류 : urbandict.py

import urbandict 
ur = urbandict.define("ice") 

오류 : 나는 색인을 처리하기 위해 시도했지만 프로그램이 멀리 그것을하지 않습니다

Traceback (most recent call last): 
    File "C:\Users\dmurp_000\Desktop\wordFuntcion.py", line 15, in <module> 
    ur = urbandict.define("ice") 
    File "C:\Python27\lib\urbandict.py", line 86, in define 
    urbanDictParser.feed(data) 
    File "C:\Python27\lib\HTMLParser.py", line 114, in feed 
    self.goahead(0) 
    File "C:\Python27\lib\HTMLParser.py", line 152, in goahead 
    if i < j: self.handle_data(rawdata[i:j]) 
    File "C:\Python27\lib\urbandict.py", line 72, in handle_data 
    self.translations[-1]['example'] += data.replace('\r', '\n') 
**IndexError: list index out of range** 

. 도움이 될 것입니다.

elif self.inside_example_section is True: 
     if len(self.translations) >= 1: 
      self.translations[-1]['example'] += data.replace('\r', '\n') 
+0

(https://github.com/novel/py-urbandict)? – 2rs2ts

+0

감사합니다 게놈, 이건 내 문제가 해결 !! – dmurphy

+0

'urbandictionary.com'이 html 마크 업을 변경 한 것 같습니다 (webarchive의 이전 마크 업 참조) (http://web.archive.org/web/20140101045756/http://www.urbandictionary.com/define. 현재 HTML 마크 업에서 작동하는 ['urbandictionary.py'] (https://gist.github.com/zed/9903390)입니다. ['urbandictionary.py']에 대한 pull 요청에 자유롭게 적용하십시오. py-urbandict'] (https://github.com/novel/py-urbandict) – jfs

답변

-1

...

elif self.inside_example_section is True: 
     self.translations[-1]['example'] += data.replace('\r', '\n') 

최근의 HTML 태그를 변경. Development version (urbandict 0.2)은 새로운 html 마크 업을 지원합니다. 당신은 pip를 사용하여 설치할 수 있습니다 :

$ pip install -e git+https://github.com/novel/py-urbandict#egg=urbandict 

예 : 당신이 [이 GitHub의 프로젝트]를 사용하고

$ urbandicli Honorificabilitudinitatibus 

1. honorificabilitudinitatibus honorableness Used by Shakespeare in Loves Labors Lost (Costartd; Act V Scene I) 
    Examples: 
    * For thou art not so long by the head as 
    honorificabilitudinitatibus: thou art easier swallowed than a 
    flap-dragon.
+2

사용하려고 시도한 예외를 쳤을 때 다운로드 한 라이브러리를 편집하는 것은 일반적으로 권장되지 않습니다. 어떤 새로운 개발자가 OP에 뒤이어 왔고이 라이브러리를 알고 있다면 그들은 git에서하는 것처럼 작동 할 것이라고 기대할 것이고, 아마도이 문제를 일으키는 것을 인식하지 못할 것이다. –

관련 문제