python - Merging txt files matchs conditions -


i have list of files in txt format in python in app this:

['pr00-1.txt', '900-2.txt', 'pr00-2.txt', '900-1.txt', 'pr900-3.txt', '00-3.txt'] 

i'm trying merge 00 files ['pr00-1.txt', 'pr00-2.txt', '00-3.txt'] in 1 00.txt file.

same 900 files , on regardless on pr or -*.txt, * number. tried using split it's not helping.

any idea how it?

i think want. find 00 files regular expression open 00.txt , write files it. note solution isn't generalized xx pattern, , fails if 1 of files doesn't exist. i'll leave rest you.

import re  open('00.txt.', 'w') outfile:     filenames = ['pr00-1.txt', '900-2.txt', 'pr00-2.txt', '900-1.txt',          'pr900-3.txt', '00-3.txt']     filename in filenames:         match = re.search(r'(^|[^0-9])00.*.txt', filename)         if (match):             open(filename) infile:                 outfile.write(infile.read()) 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -