St.text_area issue

I’m trying to read file, update, then save.

with open(r’C:\Test\test.txt’, ‘r’) as f:
input =

text1 = st.text_area(‘SQL Statement as below:’, input, 500)

if st.button(‘Save’):
with open(r’C:\Test\test.txt’, ‘w’) as f:

but it only works at first ‘Save’ button clicked.

when I tried to update the text1 and click ‘Save’ button at the second time, text1 still shows the previous value. the change is not saved.

Hi @calvin , what do you mean by tried to update the text1? How are you updating it? Are you expecting the lines

with open(r’C:\Test\test.txt’, ‘w’) as f:

to update the text? If so, wouldn’t it have the same text?

I’m trying to read file content, and put it in the text area so I can update it, then write the update content back to the file if ‘save’ button clicked.

please see the screen below:

1, the first time, the file content is empty, if I input ‘the first time’ and click save. and it writes update content into the file.

2, but if I change content again, like input ‘Second time’, then click ‘savf’, the text in text area will show ‘the first time’ which is previous value.