[Python] prompt function of prompt_toolkit displaying a truncated string

Discussão em 'Python' iniciado por Stack, Março 29, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to read the text of a pdf file then display this text as an editable string on the command line. I tried to achieve this using the "pdf_plumber" and "prompt_toolkit" modules. The following is the content of the pdf and the code of my program:

    sample.pdf:

    Section 1
    This is a sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence.
    Section 2
    This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence.
    Section 3
    This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence.
    Section 4
    This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence.
    Section 5
    This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence.


    test.py:

    import pdfplumber
    from prompt_toolkit import prompt

    doc = pdfplumber.open("sample.pdf")

    content_list = []
    for num in range(0, len(doc.pages)):
    content_list.append(doc.pages[num].extract_text())

    string = content_list[0]
    for num in range(1, len(content_list)):
    string += content_list[num]

    string = "".join(content_list)

    retrieve_input = prompt("Display the string:\n\n", default=string)

    print(retrieve_input)


    The problem is after executing the code above the editable string being displayed is truncated like so: Truncated string on command line

    But when I press the up arrow key in the command line, I can see the rest of the string: Moved all the way up in the command line

    Is there a way to display the entire string using the "prompt()" function of the test.py file without it being truncated initially? This function used to display all of the editable string without being truncated before, but now it does not. I am not sure if I accidentally edited some system settings during development. I tried uninstall then reinstall the "prompt_toolkit" module but the problem still persists

    Any help is appreciated. Thank you

    Continue reading...

Compartilhe esta Página