-3
これは、あなたはすでにあなたがos.listdir()
を使用することができ、今os
をインポートしたコードプログラム、それが全てというディレクトリ内のファイルとそのサブディレクトリを開きますすぐ
import os
import time
import Tkinter, tkFileDialog
Tkinter.Button(subframe, text = "Browse", command = self.loadtemplate, width = 10).pack()
def loadtemplate(self):
filename = tkFileDialog.askopenfilename(initialdir = "Desktop",title = "Select file",filetypes = (("text files","*.txt"),("all files","*.*")))
counts = dict()
t1 = time.time()
with open(filename, 'r') as f:
for line in f:
words=line.lower()
words = words.split()
last_pos = f.tell()
last_pos = last_pos
print last_pos
for word in words:
if word not in counts:
counts[word] = 1
else:
counts[word] += 1
con=True
while con:
find=raw_input("Enter word to be searched")
if find in counts:
print find, " occurs", counts[find]
else:
print "not found:"
inc=raw_input("Want to continue y/n:")
if inc=='y':
con=True
else :
con=False
あなたの質問は..ですか? –
質問には質問はありません。 –