how do i check if a file exists with python?

Gary Herron gherron at aw.sgi.com
Thu Dec 28 19:57:36 EST 2000


Scott Hathaway wrote:
> 
> I have searched Deja, looked in two pyton books, and searched the python.org
> site trying to find out this simple question.
> 
> Can someone please give me the call and the module it lives in?
> 
> Thanks,
> Scott
> 
> --
> http://www.python.org/mailman/listinfo/python-list

This should work for any recent version of Python:
  import os.path
  os.path.isfile('somefile')

See the documentation of module os.path for several other isXXX
procedures.

-- 
Dr. Gary Herron <gherron at aw.sgi.com>
206-287-5616
Alias | Wavefront
1218 3rd Ave, Suite 800, Seattle WA 98101




More information about the Python-list mailing list