[Tutor] not operator

Alan Gauld alan.gauld at btinternet.com
Fri Sep 19 01:11:34 CEST 2008


"jeremiah" <jeremiah.jester at panasonic.aero> wrote

>i want to check if a dir does not exist. how do i change this 
>statement
> to evaluate is NOT existing? ==False or ! operator. Also, is 
> sys.exit
> appropriate to use to quit out of the program?
>
> if(os.access(target_dir, os.F_OK)):
> print "File does not exist!"
> sys.exit

if not os.access(target_dir, os.F_OK):
  print "File does not exist!"
  sys.exit

Should work. Although you claim a file does not exist but
seem to be testing a directory?!

Also did you see the os.path.exists() function?

You might find that useful.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld


>
>
>
> Disclaimer: The information contained in this transmission, 
> including any
> attachments, may contain confidential information of Panasonic 
> Avionics
> Corporation.  This transmission is intended only for the use of the
> addressee(s) listed above.  Unauthorized review, dissemination or 
> other use
> of the information contained in this transmission is strictly 
> prohibited.
> If you have received this transmission in error or have reason to 
> believe
> you are not authorized to receive it, please notify the sender by 
> return
> email and promptly delete the transmission.
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




More information about the Tutor mailing list