Introduction to using the OS. path. isdir () function in the Python Programming Language

Source: Internet
Author: User

The Python programming language is a very powerful computer language. The Python programming language has very simple skills in actual operations, today we will introduce how to use the OS in the Python programming language. path. isdir () function to determine whether the path is a directory.

Determine whether the program is a directory in the Python Programming Language

In the Python programming language, you can use the OS. path. isdir () function to determine whether a path is a directory. The function prototype is as follows.

 
 
  1. os.path.isdir(path) 

The parameter meanings are as follows. Path. The following example checks whether E: \ book \ temp is a directory.

 
 
  1. >>> import os  
  2. >>> os.path.isdir('E:\\book\\temp') 

Determine whether E: \ book \ temp is a directory

 
 
  1. True 

Table E: \ book \ temp is a directory

Determine whether the Python programming language is a file

In the Python programming language, you can use the OS. path. isfile () function to determine whether a path is a file. The function prototype is as follows.

 
 
  1. os.path.isfile(path) 

The parameter meanings are as follows. Path: The path to be determined. The following example checks whether E: \ book \ temp is a file.

 
 
  1. >>> import os  
  2. >>> os.path.isfile('E:\\book\\temp')   

Determine whether it is a file

 
 
  1. False 

E: \ book \ temp is not a file or above. It is an introduction to how to use the Python programming language to determine whether it is a directory or whether it is a directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.