os.path.exists()

如果存在,返回True,否则返回False

  1. import os.path
  2. from os import path
  3. def main():
  4. print("file exist: " + str(path.exists('Beakman.txt')))
  5. print("File exist: " + str(path.exists('career.Beakman.txt')))
  6. print("directory exists: " + str(path.exists('BeakmanDirectory')))
  7. if __name__ == "__main__":
  8. main()

os.path.isfile()

如果存在,返回True,否则返回False

  1. import os.path
  2. from os import path
  3. def main():
  4. print("Is it File? " + str(path.isfile('Beakman.txt')))
  5. print("Is it File? " + str(path.isfile('BeakmanDirectory')))
  6. if __name__ == '__main__':
  7. main()

os.path.isdir()

如果存在,返回True,否则返回False

  1. import os.path
  2. from os import path
  3. def main():
  4. print ("Is it Directory?" + str(path.isdir('Beakman.txt')))
  5. print ("Is it Directory?" + str(path.isdir('BeakmanDirectory')))
  6. if __name__== "__main__":
  7. main()