Jonas Melian wrote:
> Kent Johnson wrote:
> 
>>>Is there any way of checking all possible errors, show you all error
>>>messages, and then exit.
>>
>>I don't understand your question. Can you give an example of what you would 
>>like to do?
>>
> 
> The idea was check all exceptions before of exit. I made it :)
> 
> flag_error = False
> for x in [dir_lo, dir_k, dir_x]:
>     try:
>         os.listdir(x)
>     except OSError, err_o:
>         flag_error = True
>         print "Error! %s: %r" % (err_o.strerror, err_o.filename)
> 
> if flag_error:
>     sys.exit()
> 
> Now, I have a dudes:
> 
> 1) Is it necessary use .exit() with some value (as 1) for indicate that
> has been an error?

The argument to sys.exit() is the exit status of your program. exit() is the 
same as exit(0). If you 
want to signal to other programs that you exited with an error then use a 
different value.
> 
> 2) With .listdir() the exception can checks if the directory exist, but
> how check if there are files in that directory too?

Look at the result of the call to listdir(), e.g.
   if len(os.listdir(x)) == 0:
     flag_error = True
     print "Error: Empty directory"

Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to