How can I have text (file extention) after an input option in python?

Viewed 34

Soo, How can I have text display after an input()?

I'll explain with an example:

import os

docname = input(f"Where do you wanna save your document? {os.path.dirname(os.path.realpath(__file__))\\images\\")

As user is typing, the .pdf extension is after what they typed (am not native English)

Where do you wanna save your document? C:\Users\Public\Downloads\project\(here user can type).pdf

(I don't worry about the extention; docname = docname + ".pdf"

I saw this question, but that doesnt answer my question (This isn't a duplicate of that, because that doesnt appear as I type). Here's how far i've came:

text = f"File destination: {os.path.dirname(os.path.realpath(__file__))}\\images\\"
while True:
    answer = input(text)
    fileExtension = ".pdf"
    while not answer:
        pass
        # print(f"\33[1A\33[{len(fileExtension)}C {fileExtension}")
        # print("\033[A\033[A")
    else:
        break

The main problems are that:

  1. This doesnt run lol
  2. I can't (or don't know how to) identify the length of characters as user is typing. Also, I dunno if I would need it, but it's probably needed to determine if it has to print(f"\33[1A\33[{len(input)}]C)
  3. The while loop doesn't appear as the input is running. If I would do more research, I maybe will figure out how to run 2 lines at the same time, but then there's gonna be a way more simple answer.
  4. Even if I had all of these together, would it run at all? Or is the cursor jumping left and right without any possible input
0 Answers
Related