| | |
how to ingrate my code to read txt file in dirctory(folder)and subdirectory? PLZ help
![]() |
•
•
Join Date: Mar 2008
Posts: 16
Reputation:
Solved Threads: 0
how to ingrate my code to read txt file in dirctory(folder)and subdirectory? PLZ help
0
#1 Mar 18th, 2008
how to ingrate my code to read text in in parent folder contain sub folders and files for example folder name is cars and sub file is Toyota,Honda and BMW and Toyota contain file name Camry and file name corolla, file name Honda contain folder accord and BMW contain file name X5
Is there way to enter name of parent folder(cars) and search in all sub folder(Toyota,Honda and BMW) and files ?
please help ASAP
code is find most frequent word in one text file and print them in decrease order
and I wont it to find most frequant word in all text files (together) under specific folder
Is there way to enter name of parent folder(cars) and search in all sub folder(Toyota,Honda and BMW) and files ?
please help ASAP
code is find most frequent word in one text file and print them in decrease order
and I wont it to find most frequant word in all text files (together) under specific folder
Python Syntax (Toggle Plain Text)
# count words in a text and show the first ten items # by decreasing frequency # sample text for testing import sys import string import re file = open ("arb.txt", "r") text = file.read ( ) file.close ( ) word_freq = {} word_list = text.split() for word in word_list: # word all lower case word = word.lower() # strip any trailing period or comma word = word.rstrip('.,/"-_;\[]()') # build the dictionary count = word_freq.get(word, 0) word_freq[word] = count + 1 # create a list of (freq, word) tuples freq_list = [(freq, word) for word, freq in word_freq.items()] # sort the list by the first element in each tuple (default) freq_list.sort(reverse=True) for n, tup in enumerate(freq_list): # print the first ten items if n < 10: freq, word = tup print freq, word
•
•
Join Date: Jul 2006
Posts: 608
Reputation:
Solved Threads: 149
Re: how to ingrate my code to read txt file in dirctory(folder)and subdirectory? PLZ help
0
#2 Mar 18th, 2008
![]() |
Other Threads in the Python Forum
- Previous Thread: pyGTK and the Mandate of Sudo
- Next Thread: uplaoding an image using a button
| Thread Tools | Search this Thread |
alarm ansi anydbm app assignment backend beginner binary bluetooth character cipher cmd coordinates customdialog cx-freeze data decimals development directory dynamic exe feet file float format function generator getvalue gnu graphics halp handling heads homework http ideas input ip itunes java keycontrol leftmouse line linux list lists loop maintain maze millimeter module mouse number numbers output parsing path pointer prime programming progressbar push py2exe pygame pymailer python queue random recursion recursive schedule screensaverloopinactive script slicenotation sqlite ssh statistics string strings sudokusolver text thread time tlapse tuple ubuntu unicode url urllib urllib2 variable ventrilo vigenere web webservice wikipedia write wxpython xlib xlwt





