Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文件名匹配方法 #3

Open
limboinf opened this issue Jan 13, 2016 · 0 comments
Open

文件名匹配方法 #3

limboinf opened this issue Jan 13, 2016 · 0 comments

Comments

@limboinf
Copy link
Owner

如在某个路径下列出.py文件,可通过如下方法:

  1. 正则
  2. startswith& endswith
  3. glob 模块
  4. fnmatch模块

如下:

pyfiles = [name for name in os.listdir('somedir')
        if name.endswith('.py')]


import glob
pyfiles = glob.glob('somedir/*.py')

from fnmatch import fnmatch
pyfiles = [name for name in os.listdir('somedir')
            if fnmatch(name, '*.py')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant