1

ディレクトリ内の複数のテキスト ファイルを開き (raw_input)、名前を付け (ドキュメント 1、ドキュメント 2...)、「OR」を使用して 2 つの単語を検索し (raw_input)、検索語を (文字なしで) 入力したいと考えています。 .,/"" 小文字の単語のみ) およびリストまたは新しいテキスト ファイル内の単語を含むファイルの名前:

ファイルを辞書に入れようとしましたが、それがばかげた考えかどうか本当にわかりませんか?

ユーザーがすべてのファイルで (raw_input を介して) 1 つまたは 2 つの単語を同時に検索できるようにする方法がわかりません。助けてくれますか、ヒントを教えてください。

次のようなものを印刷したい:

SearchWord "ドキュメント 1、python.txt で見つかりました SearchWord "ドキュメント 3、foobar.txt で見つかりました

import re, os


path = raw_input("insert path to directory :")
ex_library = os.listdir(path)
search_words = open("sword.txt", "w") # File or maybe list to put in the results
thelist = []

for texts in ex_library:
    file = os.path.join(path, texts)
    text = open(file, "r")
    textname = os.path.basename(texts)
    print textname
    for names in textname.split():
        thelist.append(names)
    text.close()
print thelist


print "These texts are now open"
print "###########################"

count = 0
for y in ex_library:
    count = count + 1
print count
print "texts total"

d ={}


for x in range(count):
    d["Document {0}".format(x)] = None # I would like the values to be the names of the texts (text1.txt)
4

0 に答える 0