Sep-05-2019, 03:50 PM
Skaperen Wrote:i also want to be able to output a progress indicatorUse tqdm A Fast, Extensible Progress Bar for Python and CLI.
If i write a test,also rewrite previous code to use for loop bye using functools.partial.
from functools import partial from tqdm import tqdm import os def file_copy(file_name, path_out, buffer_size=1024000): with tqdm(total=os.path.getsize(file_name), unit='B', unit_scale=True) as pbar: with open(file_name, 'rb') as fsrc,open(f'{path_out}/{file_name}', 'wb') as fdst: for byte in tqdm(iter(partial(fsrc.read, buffer_size), b'')): fdst.write(byte) pbar.update(len(byte)) if __name__ == '__main__': path_out = 'C:/code/out' file_name = '2.1GB.rar' file_copy(file_name, path_out)Okay speed(6-sec for 2.1GB) with this buffer size as i have set to default.