Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How could I update an input field live?

I’m trying to update an input field in real-time. I don’t know how else to put it.

I’m making a sort-of shell in Python 3.11, and I have the current working directory as the input field.
This is what I have right now:

cwd0=os.getcwd()

while True:
  command_line=input(f"{cwd0}! ")

After changing directories with os.chdir, the input field doesn’t change along with it.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Really hope someone can help with this! Many thanks.

>Solution :

Put the function call in the prompt, not a variable.

command_line=input(f"{os.getcwd()}! ")

Or update the variable whenever you call os.chdir(). Variables are not automatically updated when the expression they were assigned from changes.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading