glob.glob standardization

Tim Roberts timr at probo.com
Fri Jun 29 01:47:45 EDT 2007


billiejoex <gnewsg at gmail.com> wrote:
>...
>glob.glob, instead, return file names only if given path is relative:
>
>>>> os.chdir('Desktop')
>>>> os.getcwd()
>'/home/user/Desktop
>>>> glob.glob("*")
>['file.py']
>
>...and absolute file names if given path is absolute:
>
>>>> glob.glob('/home/user/Desktop/*')
>['/home/user/Desktop/file.py']
>
>Don't you think it would be more convenient for glob.glob to return
>file names only in any case, like os.listdir do?

Martin gave you the real answer, but you should realize that your analysis
of the behavior is faulty.  In EACH case, glob.glob has returned all of the
names that exactly match your pattern.  It's not about absolute or
relative.  For example, if you do
    glob.glob( '..' )
which is a relative path, then the names you get back will be
['../xxx','../xxy','../xxz'].  They're not file names only.
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list