저는 초보자이며 비단뱀입니다.이 오류가 붙어 있습니다. 내가 잘못 된 곳을 말해 준다면 큰 도움이 될 것입니다.Python : ValueError : 2가 목록에 없습니다.
내가 같은 출력을 얻고 그러나import math
import nltk
import json
import pymongo
#import sys
import nltk.corpus
from funcs import get_name_entity
from funcs import sentiment_analysis
from funcs import get_wordlist
from funcs import get_pos_tag
def get_post(count):
data =()
client = pymongo.MongoClient("localhost", 27017) #take data from database Mongo
db = client.News_Updated #accessing the database News_Updated
db.News_Updated.find()
temp = []
#print count
if count == 0:
data = db.ndtv
elif count == 1 :
data = db.timesofindia
elif count == 2 :
data = db.hindustantimes
elif count == 3 :
data = db.asianetnews
elif count == 4 :
data = db.khabarndtv
#print data.find()
for post in data.find():
temp.append(post)
return temp
if __name__ == '__main__':
count = 0
limit = -1
while count < 5:
data = get_post(count)
count += 1
for text in data.index(2):
print text
:
Traceback (most recent call last): File "main.py", line 43, in for text in data.index(2): ValueError: 2 is not in list
여기 MongoDB를 데이터의 샘플입니다 여기 내 코드입니다.
{u'url': u'62-year-old-woman-murdered-in-tamil-nadu-s-salem-510469', u'_id': ObjectId('53551ebf39b71c444a991341'), u'data': u"Salem, Tamil Nadu:In a daring daylight murder, a 62-year-old woman was killed by two youths for a gold chain in a busy commercial locality in Salem, Tamil Nadu, police said.Dhanlakshmi was behind the counter of her husband's small shop on Arunachalaachari street in his absence when the assailants slit her throat with a knife and fled away taking the gold chain she was wearing, they said.Arunachalaachari street, dotted with jewellery, vessels and textile shops, is considered a busy commercial locality of the district. The incident sent shock waves among the locals.Deputy Commissioner of Police A G Babu visited the spot."}
도움을 주시면 대단히 감사하겠습니다.
파이썬 초보자를위한 중요한 도구 (또는 그 이상 - 초급 ...) : "import pdb; pdb.set_trace()". 로컬 변수의 이름을 디버거에 입력하여 포함해야한다고 생각하는 것을 포함하지 않는 것을 찾으십시오. –