How to open and read an unknown extension file
varnikat t
varnikat22 at gmail.com
Thu Apr 8 13:18:31 EDT 2010
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!!
On Thu, Apr 8, 2010 at 9:12 PM, Kushal Kumaran <
kushal.kumaran+python at gmail.com <kushal.kumaran%2Bpython at gmail.com>> wrote:
> On Thu, Apr 8, 2010 at 9:00 PM, varnikat t <varnikat22 at gmail.com> wrote:
> > I am trying to do this
> > if os.path.exists("*.*.txt"):
> > file=open("*.*.txt")
> > self.text_view.get_buffer().set_text(file.read())
> > else:
> > file=open("*.*.html")
> > self.text_view.get_buffer().set_text(file.read())
> >
> > It gives error *.*.txt not existing....There are two files in the folder
> > testing.pnm.txt
> > and testing.pnm.html
> > How to make it open any name and extension file and read it?
> >
>
> os.path.exists does not do pattern matching like that. Take a look at
> the glob module.
>
> --
> regards,
> kushal
>
--
Varnika Tewari
--
Varnika Tewari
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100408/7706ee79/attachment-0001.html>
More information about the Python-list
mailing list