•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 422,405 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,898 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 342 | Replies: 1
![]() |
| |
•
•
Join Date: Mar 2008
Posts: 16
Reputation:
Rep Power: 1
Solved Threads: 0
how to search in parent folder and proplem integrat to GUI( non english txt)PLZ help
#1
Mar 17th, 2008
Is python provide search in parent folder contain subfolders and files for example folder name is cars and subfile is Toyota,Honda and BMW and Toyota contain file name camry and file name corola, 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 ? how can I intgreat cod to be user interface (buttun ,text box etc) and let user to enter find most X (10,20,30 etc) frequency word and how to let user to writ parent file name to search in its container (files and folders) this is codebut unfortinatly when I wont to search in (not English text) for example (Arabic) file it will not read it probably it print text like 3ÇáäíÇÈÉ 28Ýí 11Úáì 11ÊÜÊÜãÜÉ 10ãä 10Úä 7Ãä 6ÈÓÈÈ 5ÎÈÑ 5ÇáãÓáãæä sample file in attach I use# a look at the Tkinter Text widget # use ctrl+c to copy, ctrl+x to cut selected text, # ctrl+v to paste, and ctrl+/ to select all import Tkinter as tk def most_frequant_word(): # count words in a text and show the first ten items # by decreasing frequency # sample text for testing import sys import string import re v1.set(text1.get(1.0, tk.END)) text1.delete(1.0, tk.END) 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: text1.insert(tk.INSERT, freq) text1.insert(tk.INSERT, word) text1.insert(tk.INSERT, "\n") freq, word = tup print freq, word root = tk.Tk(className = " most_frequant_word") # text entry field, width=width chars, height=lines text text1 = tk.Text(root, width=50, height=20, bg='green') text1.pack() # function listed in command will be executed on button click button1 = tk.Button(root, text='result', command=most_frequant_word) button1.pack(pady=5) # define a variable to hold the label text v1 = tk.StringVar() # label text will always be the textvariable's value # width/height in char size label1 = tk.Label(root, textvariable=v1, width=50, height=20) label1.pack(pady=5) # start cursor in text1. text1.focus() root.mainloop()to inset to the text pleas I need your help for this and previous onetext1.insert(tk.INSERT, freq) text1.insert(tk.INSERT, word) text1.insert(tk.INSERT, "\n")
Last edited by alivip : Mar 17th, 2008 at 5:47 am.
•
•
Join Date: Dec 2006
Posts: 443
Reputation:
Rep Power: 2
Solved Threads: 62
Re: how to search in parent file and proplem to integrat to GUI( non english txt)PLZ help
#2
Mar 17th, 2008
You will have to use unicode strings. Here is Guido's tutorial http://docs.python.org/tut/node5.htm...00000000000000 From the tutorial, you would use
word=u"3ÇáäíÇÈÉ".encode('utf-8') if arabic uses 8 bits per byte.
word=u"3ÇáäíÇÈÉ".encode('utf-8') if arabic uses 8 bits per byte.
Last edited by woooee : Mar 17th, 2008 at 9:27 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
adsense adult advertising biometrics blogging bomb book business coding copyright cult of the dead cow data development engine environment failure forum google hacking internet legal malware marketing mcafee microsoft monetization msn news operating pagerank people-powered phishing photo privacy publishing revenue search security seo sex silverlight software spyware support system technical web webmaster wiki yahoo
- Previous Thread: Help with Appending Number Matrix
- Next Thread: Puzzled...???


Hybrid Mode