Application of Python Glob module

Source: Internet
Author: User
Tags glob

Recent projects almost, back to learn the basics of knowledge, today saw, Glob module feel very good, write to Memo.

Glob module can help us to quickly find the file of the system, or view, not to call its own OS, module, quick and easy, support simple regular: Find files only use three matches: "*", "?", "[]". "*" matches 0 or more characters; "?" Matches a single character; "[]" matches a character in a specified range, such as: [0-9] matches a number.

Examples of:>>> import glob>>> print Glob.glob ('/tmp/* ') ['/tmp/xiaoluo.txt ', '/tmp/yum.log ', '/tmp/ TMPT4PKWG ', '/tmp/paramiko1.py ', '/tmp/sess_fa2cc319aa24dc8671e9cb231253d118 ', '/tmp/mysql.sock ', '/tmp/pear ', '/ tmp/sess_6c9be7618e7d3743a1767dc523ad8060 ']>>> print glob.glob ('/tmp/*.txt ') ['/tmp/xiaoluo.txt '] simply write a function , when entering a value, list all the files inside: #!/usr/bin/env python#coding=utf-8import globdef Get_dir (file_list): Return Glob.glob ('%s/* '% ( file_list)) If __name__ = = ' __main__ ': Print Get_dir ('/tmp ') so we can call this module directly when we use it to print the files in this directory.

This article is from the "Little Luo" blog, please be sure to keep this source http://xiaoluoge.blog.51cto.com/9141967/1618942

Application of Python Glob module

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.