Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Another error

  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    40
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Another error

    I feel like a huge newbie.
    I can't figure out what's going wrong here.
    Code:
    	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?

    Above shows what happens, at '>>>' if I typed something that is not a command that error would've shown.
    Last edited by pippin418; 05-09-2010 at 08:31 AM.

  • #2
    Regular Coder Samhain13's Avatar
    Join Date
    Aug 2008
    Location
    Pilipinas
    Posts
    169
    Thanks
    4
    Thanked 18 Times in 18 Posts
    I don't know. But trying to remove a directory using part of your code gives me:

    Code:
    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:

    Code:
    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
    I am a Man of Truth. I am a Free Human Person. I am a Peacemaker.
    ** Independent Multimedia Artist in Pasig **

  • Users who have thanked Samhain13 for this post:

    pippin418 (05-09-2010)

  • #3
    New Coder
    Join Date
    Dec 2009
    Posts
    40
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Ah, it was error code 21. It told me 256 when I tested it. Well, nevermind then.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •