最後にテキストを抽出するためにウォーキングスクリプトを得た
#我々はタイトル2アンダーラインのみのファイルとプリントをreadinているプログラムで例えば、テキストファイル #から特定の行を読み、タイトル4 #ログファイルには空白行が含まれています #ログファイルの例 #タイトル #1 #dklfjsdkl; #G #sdfzsdfsdf #sdfsdfsdf #dsfsdfsd #dfsdf # #タイトル #2 # #dfdf #dfdf #dfdf #DF #DFD #D # #1 TITLE3 # sdfdfd 位 #のDFD # #のDFD # #タイトル #dfdfd 4 #dfkdfkd #dfdkjmd #dfdkljm
in_list= []
while True:
i = raw_input("Enter title to be extracted (or Enter to quit): ")
in_list.append(i)
if not i:
break
print("Your input:", i)
print("While loop has exited")
in_list.remove(i)
print "Input list", in_list
flist = []
with open("C:\\text.txt", 'r') as inp:
#read the flie and storing into the list
flist =inp.readlines()
inp.close()
#making everything in the list to lower case
flist = map(lambda x:x.lower(),flist)
flist = [s.strip("\n") for s in flist]
print flist
# printing the complete log file from the list. Since once we put the vlaue in the list the new line character will be \ appended in the list element.
#hence striping with \n character
# for i in flist:
# print i.strip("\\n")
for j in range(len(in_list)):
result = any(in_list[j] in word for word in flist)
if result:
i_index = flist.index(in_list[j])
flag = 0
with open("C:\\output.txt",'a') as f1:
f1.write(flist[i_index])
f1.write("\n")
while flag ==0:
if "title" in flist[i_index+1]:
flag =1
else:
i_index += 1
f1.write(flist[i_index])
f1.write("\n")
i_index += 1
f1.close()
あなたには、いくつかの例のログを表示することができますか?あなたの問題文はあまりにも一般的すぎて、他人を助けることができません。 – meatspace
あなたが実装したコードを投稿してください。私たちはあなたのコードを書くつもりはありません。コードに問題がある場合は、ここにエラーを投稿してください。 – Harwee