Python 3.5 glob.glob() 2nd param (*) and how to detect files/folders beginning with "."?

Jussi Piitulainen jussi.piitulainen at helsinki.fi
Tue Jul 26 12:26:55 EDT 2016


Malcolm Greene <python at bdurham.com> writes:

> In reading Python 3.5.1's glob.glob documentation[1] I'm puzzled by the
> following:
>  
> 1. The signature for glob.glob() is "glob.glob(pathname, *,
>    recursive=False)". What is the meaning of the 2nd parameter listed
>    with an asterisk?

It's not a parameter. It's special syntax to indicate that the remaining
parameters are keyword-only.

> 2. Is there a technique for using glob.glob() to recognize files and
>    folders that begin with a period, eg. ".profile"? The documentation
>    states: "If the directory contains files starting with . they won’t
>    be matched by default.". Any suggestions on what the non-default
>    approach is to match these type of files?

Glob with a pattern that starts with a dot. Glob twice if you want both
kinds. Or look into that fnmatch that is referenced from glob
documentation and said not to consider leading dots special.

> [1] https://docs.python.org/3/library/glob.html

.



More information about the Python-list mailing list