程序未显示任何输出

时间:2013-10-02 17:20:38

标签: python output whoosh

import os, os.path
from whoosh.index import create_in
from whoosh.fields import *
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)

if not os.path.exists("indexdir"):
    os.mkdir("indexdir")


ix = create_in("indexdir", schema)
writer = ix.writer()
writer.add_document(title=u"First document", path=u"/a",
                 content=u"This is the first document we've added!")
writer.add_document(title=u"Second document", path=u"/b",
                 content=u"The second one is even more interesting!")
writer.commit()
from whoosh.qparser import QueryParser

with ix.searcher() as searcher:
    query = QueryParser("content", ix.schema).parse("first")
    results = searcher.search(query)
    results[0]

看起来没问题,但它没有显示任何结果。

2 个答案:

答案 0 :(得分:1)

我想你最后一行是:

print results[0]

答案 1 :(得分:0)

Python要求您使用print显式打印输出:

print results[0]

但请注意,上面的代码适用于Python 2.x.在Python 3.x中,print已转换为function

print(results[0])