Resuming in exception handling

Brian Quinlan brian at sweetapp.com
Mon Apr 16 23:51:41 EDT 2001


Just restructure your code:

LWPath = 'C:\\LAND WARRIOR 1.0'

flist = glob.glob( LWPath + '\\LW*.txt')

for fname in flist:
	print 'removing ' + fname
	try:
		os.remove(fname)
	except OSError:
    		print('skipping ' + fname)
		flist.remove(fname)

-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Lucas Vogel
Sent: Monday, April 16, 2001 8:12 PM
To: python-list at python.org
Subject: Resuming in exception handling


-----BEGIN PGP SIGNED MESSAGE-----

I want to resume the for statement in the chunk of code I am running
in this (very simple) script.
Here's what I have so far...

<code snippet>
import os, glob

#place all LW*.txt files in list and kill them

LWPath = 'C:\\LAND WARRIOR 1.0'
try:
    flist = glob.glob( LWPath + '\\LW*.txt')

    for fname in flist:
        print 'removing ' + fname

        os.remove(fname)

    del flist

except OSError:
    print('skipping ' + fname)
    flist.remove(fname)


</code snippet>


I get an OSError about a file permission on one of the files it tries
to delete. When it gets that exception I want it to simply move on to
the next file. How do I do that?

Thanks

===============================
Lucas Vogel




-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQCVAwUBOtu0jClA8LjISNKLAQEfEgP+NhC1PQ2hysuxLPap764rdd/oVGhM0YGT
Y44iwcHvi09uQhqu6+sgUu3ADYMdz4bXIRzteEdaI0wW9VjhHEXrCCFOuX6dfpEM
bJNxSt0LBXYQJluBIq+o6AmDTkL5PLXCCeRBrmk0nxotDYej9+d39YKd/uN84kYA
PcQNwV6AP5g=
=xR4G
-----END PGP SIGNATURE-----



-- 
http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list