Q:

How to open files with an incremental numbers?

Right now I'm doing this:
filenames = ['ch01.md', 'ch02.md', 'ch03.md', 'ch04.md', 'ch05.md', 'ch06.md']
with open('chall.txt', 'w') as outfile:
   for fname in filenames:

But I have many files written as chxx.md (until ch24.md). Is there any what to modify the script using ranges? So I don't have to type in all the files names?

A:

You can probably use glob. It's an easy way to collect files with the use of wildcard characters.
import glob
filenames = glob.glob('/yourDirectory/ch*.md') # Will give you a list of all the file names
with open('chall.txt', 'w') as outfile:
   for fname in filenames:

