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.
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.