How to tell if I can open a file or not
Mikael Olofsson
mikael at isy.liu.se
Thu Jun 8 10:26:43 EDT 2000
On 08-Jun-00 Skip Hollowell wrote:
> I have a indexer that I am writing that goest through a user-specified
> directory and all subdirectories and indexes all the .htm* file contained
> therein. This works great until I get to a file that someone has chmod-ed
> so that I can't read it. Then I bomb after the open().
>
> Is there a way I can check the attrbutes of the file before I open it?
> This
> is easy enough in c or perl, but have yet to find an equivalent in Python.
Well, the easiest thing you can do is to wrap your offending code inside
a try-clause, like so:
try:
offending_code
except:
deal_with_breakdown
If you really want to check the settings of the file, I guess you should
read up on module os, and especially os.stat. Also, take a look at module
stat.
Good luck!
/Mikael
-----------------------------------------------------------------------
E-Mail: Mikael Olofsson <mikael at isy.liu.se>
WWW: http://www.dtr.isy.liu.se/dtr/staff/mikael
Phone: +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
Date: 08-Jun-00
Time: 16:09:03
This message was sent by XF-Mail.
-----------------------------------------------------------------------
More information about the Python-list
mailing list