>>> import os
>>> import itertools
>>>
>>> def list_files(path):
... # Здесь из директории выделяются только файлы
... fulls = (os.path.join(path, i)
... for i in os.listdir(path))
... return filter(os.path.isfile, fulls)
...
>>> def file_contents(path):
... # Здесь преобразуешь имя файла в поток его строк
... return ['file', 'contents'] # как бы открыл и вернул
...
>>> def stream_data(seq):
... # Здесь преобразуешь поток строк в поток выделенных данных
... return ['stream', 'data'] # как бы выделил и вернул
...
>>> def doc_write(doc, pos, data):
... # Здесь записываешь в документ и позицию выделенные данные
... print('Writing to', doc)
... print(' to position', pos)
... print(' start', data, 'end')
...
>>> def dir_to_doc(path, doc):
... # Здесь происходит преобразование содержимого директории
... # в записанные в документе выделенные данные
... positions = ((1, i) for i in itertools.count(1))
... dsequence = (stream_data(file_contents(i)) for i in list_files(path))
... for pos, dat in zip(positions, dsequence):
... doc_write(doc, pos, dat)
...
>>> dir_to_doc('/etc', 'file.xls')
Writing to file.xls
to position (1, 1)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 2)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 3)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 4)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 5)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 6)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 7)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 8)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 9)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 10)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 11)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 12)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 13)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 14)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 15)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 16)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 17)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 18)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 19)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 20)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 21)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 22)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 23)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 24)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 25)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 26)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 27)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 28)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 29)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 30)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 31)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 32)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 33)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 34)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 35)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 36)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 37)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 38)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 39)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 40)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 41)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 42)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 43)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 44)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 45)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 46)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 47)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 48)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 49)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 50)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 51)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 52)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 53)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 54)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 55)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 56)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 57)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 58)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 59)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 60)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 61)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 62)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 63)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 64)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 65)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 66)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 67)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 68)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 69)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 70)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 71)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 72)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 73)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 74)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 75)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 76)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 77)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 78)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 79)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 80)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 81)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 82)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 83)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 84)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 85)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 86)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 87)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 88)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 89)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 90)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 91)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 92)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 93)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 94)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 95)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 96)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 97)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 98)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 99)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 100)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 101)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 102)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 103)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 104)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 105)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 106)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 107)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 108)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 109)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 110)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 111)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 112)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 113)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 114)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 115)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 116)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 117)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 118)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 119)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 120)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 121)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 122)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 123)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 124)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 125)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 126)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 127)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 128)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 129)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 130)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 131)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 132)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 133)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 134)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 135)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 136)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 137)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 138)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 139)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 140)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 141)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 142)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 143)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 144)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 145)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 146)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 147)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 148)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 149)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 150)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 151)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 152)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 153)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 154)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 155)
start ['stream', 'data'] end
Writing to file.xls
to position (1, 156)
start ['stream', 'data'] end
>>>