A question on the creation of list of lists

Chris Angelico rosuav at gmail.com
Thu Apr 23 10:23:14 EDT 2015


On Fri, Apr 24, 2015 at 12:12 AM, Dave Angel <davea at davea.name> wrote:
> On 04/23/2015 08:36 AM, Gregory Ewing wrote:
>>
>> Jean-Michel Pichavant wrote:
>>>>
>>>> From: "subhabrata banerji" <subhabrata.banerji at gmail.com>
>>>>
>>>> list_of_files = glob.glob('C:\Python27\*.*')
>>
>>  >
>>>
>>> 1/ Your file pattern search will not get files that do not have any
>>> dot in
>>> their name
>>
>>
>> Actually, on Windows, it will. (This is for compatibility with
>> MS-DOS 8.3 filenames, where the dot wasn't actually stored, so
>> there was no distinction between a filename with a dot and an
>> empty extension, and a filename with no dot.)
>>
>
> That's certainly true at the command line in Windows DOS box, but I'd be
> astounded if glob used the same logic, even on Winodows.

Easily verified, as I have a Windows box handy.

>>> glob.glob("C:\\Python27\\*")
['C:\\Python27\\DLLs', 'C:\\Python27\\Doc', 'C:\\Python27\\include', 'C:\\Python
27\\Lib', 'C:\\Python27\\libs', 'C:\\Python27\\LICENSE.txt', 'C:\\Python27\\NEWS
.txt', 'C:\\Python27\\python.exe', 'C:\\Python27\\pythonw.exe', 'C:\\Python27\\p
ywin32-wininst.log', 'C:\\Python27\\README.txt', 'C:\\Python27\\Removepywin32.ex
e', 'C:\\Python27\\Scripts', 'C:\\Python27\\tcl', 'C:\\Python27\\Tools', 'C:\\Py
thon27\\w9xpopen.exe']
>>> glob.glob("C:\\Python27\\*.*")
['C:\\Python27\\LICENSE.txt', 'C:\\Python27\\NEWS.txt', 'C:\\Python27\\python.ex
e', 'C:\\Python27\\pythonw.exe', 'C:\\Python27\\pywin32-wininst.log', 'C:\\Pytho
n27\\README.txt', 'C:\\Python27\\Removepywin32.exe', 'C:\\Python27\\w9xpopen.exe
']

Jean-Michel's right, *.* implies a contained dot.

Also, it's worth noting that just * works fine at the command line,
too. The use of *.* to mean "everything" is outdated and should be
considered deprecated (but then, so should backslashes as directory
separators IMO).

ChrisA



More information about the Python-list mailing list