2017-10-04 6 views
-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 
+0

あなたの質問は..ですか? –

+0

質問には質問はありません。 –

答えて

0

ですアクセスしたいディレクトリの内容を取得します。連続ループは、タスクの実行に役立ちます。

+0

それは働いた... – akshay