擅长:python、mysql、java
<p>最好的方法是:</p>
<ol>
<li>Glob以<code>sync</code>开头的所有文件</li>
<li>按数字组件对列表排序</li>
<li>把它分成800块</li>
</ol>
<p>既然你已经了解了globbing,剩下的就是:</p>
<pre><code>import glob
import re
from itertools import izip_longest
# https://docs.python.org/2/library/itertools.html#recipes
def grouper(iterable, n, fillvalue=None):
"Collect data into fixed-length chunks or blocks"
# grouper('ABCDEFG', 3, 'x') > ABC DEF Gxx
args = [iter(iterable)] * n
return izip_longest(fillvalue=fillvalue, *args)
def sorter(x):
return int(re.search('(\d+)',x).groups()[0])
files = glob.glob('sync*.tif')
sorted_files = sorted(files, key=sorter)
in_batches = list(grouper(sorted_files, 800))
</code></pre>
<hr/>
<p>由于模式始终是<code>sync_</code>(在您编辑之后),您可以将上面的代码简化为以下内容:</p>
^{pr2}$