Flyzone wrote: > Hi > I'm trying to delete some files, but i get an exception error if the > file don't exist. > I can use an {if fileexist(file) then delete}, but it will get cpu > time. > So i catch the exception with: > try: os.remove(filename) > except EnvironmentError: error=1 > If i just want to avoid the output error, is this the right way to > write the code? > I don't care of get if is in error, but an "except EvironmetError" > without the ":" will give me a sytax error. > Am I too much complicated? :-) > > Thanks in advance >
You got it! Not to complicated--just right. I would make the tiniest of changes for style and speed: try: os.remove(filename) except EnvironmentError: pass But what you have already is fine. James -- http://mail.python.org/mailman/listinfo/python-list