Python tips for getting fixed the number of file types contained below

Source: Internet
Author: User
Tags glob

Encounter such a problem. I want to count the number of py files in a folder.

Can it be solved with python? Answer, can.

Workaround, use Glob

The code is as follows:

Import Globpath_file_number=glob.glob (pathname=r ' *.py ') print (path_file_number) print (len (path_file_number))

Very simple few lines of code,.

First step, import the Glob library

The second step, using Glob below the Glob method, parameter is the path under the judgment of the file

Step Three: Print:

Results:

This is consistent with the number of py files in my current directory. Python is so simple.

Open Source Address: https://github.com/liwanlei/

contact me: qq:952943386 email:[email protected] QQ Group: 194704520 new Group: 683894834

Reward support

Python tips for getting fixed the number of file types contained below

Related Article

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.