2012-02-07 53 views
3

是否有更簡單的方法來執行以下操作來遍歷xls文件,而不考慮大小寫?在迭代中忽略大小寫的方法

for file in [glob.glob(os.path.join(dir, '*.xls')), glob.glob(os.path.join(dir, '*.XLS'))]: 

回答

6

水珠和底層fnmatch有案例獨立性沒有標誌,但你可以用括號:

for file in glob.iglob(os.path.join(dir, '*.[xX][lL][sS]')): 
2

你可以做匹配的 「手動」 無glob

for file in os.listdir(dir): 
    if not file.lower().endswith('.xls'): 
     continue 
    ...