fnmatch() vs. glob.glob()

Jinghui Niu niujinghui at gmail.com
Mon Mar 7 19:53:04 EST 2016


On Monday, March 7, 2016 at 1:37:45 PM UTC-8, Ben Finney wrote:
> Jinghui Niu <niujinghui at gmail.com> writes:
> 
> > Hi, I've been studying python 3 modules. I'm a bit confused about the
> > possibly overlap between fnmatch() and glob(), they seem to achieve
> > the same goals exactly. Why duplicate?
> 
> >From the module documentation:
> 
>     Note that unlike fnmatch.fnmatch(), glob treats filenames beginning
>     with a dot (.) as special cases.
> 
>     <URL:https://docs.python.org/2/library/glob.html>
> 
> So the goals are different: 'glob.glob' has the goal of matching closer
> to the Unix meaning of glob patterns, where filenames starting with a
> "." character are conventionally treated as "hidden by default".
> 
> -- 
>  \      "We are stuck with technology when what we really want is just |
>   `\                                 stuff that works." --Douglas Adams |
> _o__)                                                                  |
> Ben Finney

Thank you for your reply. So if for a beginner learner who doesn't care so much about Unix-compliant, which one is a better choice for learning purpose?



More information about the Python-list mailing list