Seite 1 von 1

glob.glob( "*.[pyd|dll|py|pyw|pyc]" )

Verfasst: Freitag 19. August 2005, 22:31
von jens
Wie geht das richtig:

Code: Alles auswählen

print glob.glob( "D:\Python\Python24\lib\*.[pyd|dll|py|pyw|pyc]" )

Verfasst: Freitag 19. August 2005, 23:15
von Leonidas
Kennst du schon diesen Thread? glob.glob scheint mir nicht besonders ausgefeilt zu sein, das beste was ich zusammenbekomme ist print glob.glob(r'D:\Python\Python24\lib\*.py[c|d]'), wozu du noch die anderen glob Aufrufe dranleimen müsstest.

Glob fehlt wie mir scheint Grouping, am besten wäre etwas in Richtung print glob.glob("D:\Python\Python24\lib\*.(pyd|dll|py|pyw|pyc)").

Code: Alles auswählen

#!/usr/bin/env python
# -*- encoding: latin-1 -*- 

import re, os

content = os.listdir('C:\\')
pymodule = re.compile(r'.+.(dll|pyd|pyc|pyw|py)$')

possiblemodules = []
for element in content:
    if pymodule.match(element):
        possiblemodules.append(element)

print possiblemodules
Naja, diese Lösung ist irgendwie suboptimal, aber was solls. :roll: