On Thu, Apr 8, 2010 at 10:39 PM, varnikat t <varnika...@gmail.com> wrote: > Hey, > Thanks for the help.it detects now using glob.glob("*.*.txt") > Can u suggest how to open and read file this way? > > if glob.glob("*.*.txt"): > file=open(glob.glob("*.*.txt")) > self.text_view.get_buffer().set_text(file.read()) > else: > file=open(glob.glob("*.*.html")) > self.text_view.get_buffer().set_text(file.read()) > > This gives error!!
glob.glob returns a list of filenames. You need to loop over it and pass individual elements to the open function. for item in glob.glob('*.txt'): # item is a filename. pass it to open and process however you need I don't know how the set_text method works, but it sounds like it might not work right if you call it repeatedly with different filenames. -- regards, kushal -- http://mail.python.org/mailman/listinfo/python-list