Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(2)  |  Call(2)  |  Derive(0)  |  Import(0)
merge list of files into new file

        def unsplit(outfile, file_names):
    """merge list of files into new file"""

    total_size = 0
    # get total size from first lines
    for file_name in file_names:
        with open(file_name, 'r') as fh:
            total_size += int(fh.readline())

    # write numbers from partial files into outfile
    with open(outfile, 'w') as out:
        out.write(str(total_size) + '\n')  # write total num of lines
        for file_name in file_names:
            with open(file_name, 'r') as fh:
                size = int(fh.readline())
                for x in xrange(size):
                    out.write(fh.readline())

    return outfile
        


src/s/b/sbgsdk-0.5.4/sbgsdk/tests/test_tools/adder/adder_test.py   sbgsdk(Download)
def test_unsplit():
    generator.generate('numbers.txt', 11, 'random')
    file_names = adder.split('numbers.txt', 3)
    adder.unsplit('out.txt', file_names)
    assert_size('out.txt', 11)

src/s/b/sbgsdk-0.5.4/sbgsdk/tests/test_wrappers/red_adder.py   sbgsdk(Download)
    def unsplit(self, files):
        adder.unsplit(self._out_file_name(), files)
        self.outputs.output.add_file(self._out_file_name())