python - How to open files with an incremental numbers? -


right i'm doing this:

filenames = ['ch01.md', 'ch02.md', 'ch03.md', 'ch04.md', 'ch05.md', 'ch06.md'] open('chall.txt', 'w') outfile:    fname in filenames: 

but have many files written chxx.md (until ch24.md). there modify script using ranges? don't have type in files names?

you can use glob. it's easy way collect files use of wildcard characters.

import glob filenames = glob.glob('/yourdirectory/ch*.md') # give list of file names open('chall.txt', 'w') outfile:    fname in filenames: 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -