[Tutor] Cannot fix OSError (try/except)
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
>>the directory, it abandons the rest of the directory contents. I
>>tested that. The except will continue to the next file/directory in
>>list, but you've potentially skipped readable files in the directory
> 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:
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))
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.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
More information about the Tutor