| | |
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: 150
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 anydbm app beginner cipher cmd coordinates curves cx-freeze data decimals development dictionary directory dynamic error examples feet file float format function generator getvalue gui halp handling homework http images import input ip itunes java keycontrol leftmouse line linux list lists loop maintain maze millimeter module mouse number numbers output parsing path port prime programming projects push py2exe pygame pyglet pymailer pyqt python queue random recursion recursive schedule screensaverloopinactive script scrolledtext slicenotation split sqlite ssh string strings sudokusolver terminal text threading time tlapse tuple tutorial type ubuntu unicode url urllib urllib2 variable variables ventrilo vigenere web webservice wikipedia wxpython xlwt





