[Python] python-docx add_picture slowly [closed]

Discussão em 'Python' iniciado por Stack, Novembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    A total of 600 images took 100 seconds, and the generated file size was 150MB. I think it's too slow, the main reason add_picture.

    1. Can add_picture be executed in parallel?
    2. Generate multiple docx in parallel and finally merge it together?

    import time, os
    from docx import Document
    from docx.shared import Inches
    doc = Document()
    paths = ['uploads/file_path/1700000000/' + x for x in os.listdir('uploads/file_path/1700000000') if x.endswith('png')]
    at = time.time()
    for i, p in enumerate(paths):
    doc.add_heading(str(i), level=1)
    doc.add_picture(p, width=Inches(5.12))
    doc.save('D:\\Users\\User\Desktop\\1.docx')
    print(time.time() - at)

    Continue reading...

Compartilhe esta Página