Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > Python

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-09-2010, 07:21 AM   PM User | #1
pippin418
New Coder

 
Join Date: Dec 2009
Posts: 40
Thanks: 4
Thanked 0 Times in 0 Posts
pippin418 is an unknown quantity at this point
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 07:31 AM..
pippin418 is offline   Reply With Quote
Old 05-09-2010, 01:59 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
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 **
Samhain13 is offline   Reply With Quote
Users who have thanked Samhain13 for this post:
pippin418 (05-09-2010)
Old 05-09-2010, 10:08 PM   PM User | #3
pippin418
New Coder

 
Join Date: Dec 2009
Posts: 40
Thanks: 4
Thanked 0 Times in 0 Posts
pippin418 is an unknown quantity at this point
Ah, it was error code 21. It told me 256 when I tested it. Well, nevermind then.
pippin418 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:07 AM.


Advertisement
Log in to turn off these ads.