How to open and read an unknown extension file

Tim Chase python.list at
Thu Apr 8 20:35:12 EDT 2010

On 04/08/2010 12:22 PM, varnikat t wrote:
> it gives me this error
> TypeError: coercing to Unicode: need string or buffer, list found
>> Thanks for the 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(
>>          else:
>>              file=open(glob.glob("*.*.html"))
>>              self.text_view.get_buffer().set_text(

glob() returns a list of matching files, not a string.  So you 
need to iterate over those files:

   filenames = glob.glob('*.*.txt')
   if filenames:
     for filename in filenames:
     for filename in glob('*.*.html'):


More information about the Python-list mailing list