[Tutor] Cannot fix OSError (try/except)
Lloyd Kvam
pythontutor at venix.com
Sat Jan 31 17:39:09 EST 2004
Alan Gauld wrote:
>>You can pass the name of a directory. If it can't read a file
>
> within
>
>>the directory, it abandons the rest of the directory contents. I
>
> just
>
>>tested that. The except will continue to the next file/directory in
>
> YOUR
>
>>list, but you've potentially skipped readable files in the directory
>
> with
>
>>an error.
>
>
> But doesn't the OK check do the same? You would need to do a
> tree walk to avoid that, wouldn't you?
Or put the try/except inside the tarfile module. It is already doing the
tree walk. Why duplicate that logic? I'd be inclined to use the trace
to find where the exception is raised within tarfile.py and then figure
out a way to proceed with other files. The worst case is a custom version.
Possibly it could lead to an improved tarfile.py.
In Nick's original email the error is:
OSError: [Errno 13] Permission denied: '/etc/skel/tmp'
Wouldn't something like:
try:
self.add(os.path.join(name, f), os.path.join(arcname, f))
except OSError, e:
if e.errno == 13: # permission error
sys.stderr.write("permission problem on %f in %f\n" % (f, name))
else:
raise # an exception that we really want to see
make sense? The real challenge would be a mechanism to provide some custom control
to this so as not to spawn lots of custom variations.
>
> Alan G.
>
>
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice: 603-653-8139
fax: 801-459-9582
More information about the Tutor
mailing list