View Single Post
Old 05-08-2010, 08:04 PM   PM User | #2
Samhain13
Regular Coder

 
Samhain13's Avatar
 
Join Date: Aug 2008
Location: Pilipinas
Posts: 165
Thanks: 4
Thanked 18 Times in 18 Posts
Samhain13 is on a distinguished road
More stuff here: http://docs.python.org/tutorial/errors.html

For your problem:
Code:
some_file_name = "whatever"

try:
    os.remove(some_file_name)

except OSError as (errno, strerror):
    # Decide what to do based on error code:
    # File doesn't exist.
    if errno == 2:
        print "Do something..."
    # Trying to delete a directory.
    elif errno == 21:
        print "Do something else..."
    # elif errno = ??: do something else....

else:
    print "LOLWUT?"
__________________
I am a Man of Truth. I am a Free Human Person. I am a Peacemaker.
** Independent Multimedia Artist in Pasig **
Samhain13 is offline   Reply With Quote