[Tutor] Checking file existance

Sean 'Shaleh' Perry shalehperry@attbi.com
Thu, 22 Aug 2002 14:38:48 -0700


On Thursday 22 August 2002 02:34 pm, Chris Avery wrote:
> Hello all.
> I need to write some code that checks if a file exists.  If it exists, =
the
> program continues, but if it doesn't, it get's created.  I'm thinking o=
f an
> if statement like if file exists:
> =09run rest of program
> else:
> =09create file.
>
> I just don't know how to check if the file's there.
>
> Regards,
> Chris

import os.path

if os.path.exists(filename):
  print "found it"

look at the docs for os.path there are a lot of useful functions in there=
=2E