...

Another error

pippin418
05-09-2010, 07:21 AM
I feel like a huge newbie.
I can't figure out what's going wrong here.
if com == 'remf':
rem = raw_input("What file: ")
rea = raw_input("Really remove %s? (y/n): " % rem)
if rea in ('y'):
try:
os.remove(rem)
except OSError as (errno, strerror):
if errno == 256:
print "That is a directory, del deletes files. Use remd."
pen()
goto .home
elif errno == 2:
print "File does not exist."
pen()
goto .home
else:
goto .home
elif rea in ('n'):
goto .home

In that, see where rea = raw_input("Really remove %s? (y/n): " % rem) is? When I try to stimulate the 256 error, it tells me that the command I tried to input does not exist (an error message I put in my code)

So it processes my "y" as com == "y", I think.
Where is it wrong?
http://i44.tinypic.com/wiq64z.png
Above shows what happens, at '>>>' if I typed something that is not a command that error would've shown.

Samhain13
05-09-2010, 01:59 PM
I don't know. But trying to remove a directory using part of your code gives me:

errno = 21 # not 256
strerror = "Is a directory"

For development purposes, it might be a good idea to include a catch-all "else" in your except block and print out errno and strerror. This is for finding out the correct error codes for different things:


except OSError as (errno, strerror):
if errno == 21:
# What you want to say/do when trying to delete a directory.
print strerror
elif errno == 2:
# What you want to say/do when deleting a non-existent file.
print strerror
else:
# So you can find out what error codes are being returned for
# for stuff you don't know about yet.
print errno, strerror

pippin418
05-09-2010, 10:08 PM
Ah, it was error code 21. It told me 256 when I tested it. Well, nevermind then.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum