I am working on a note taking program in python and came up with a question. Is it possible to get a string variable printed on the screen, allow the user to edit that text and then change the variable into the text the user edited?
Asked
Active
Viewed 152 times
0
-
What is your user interface for your notes program ? The answer to this question might help you to have an appropriate answer. Is it ncurse (command line) program ? or a web interface ? or anything else ? Does your question is larger than just interacting into your program ? I mean you might want to extract information from a website and inject result in another program for exemple. – utopman Jan 16 '21 at 21:46
1 Answers
-1
Yes, it is possible, and it can be proved via the following scenario.
var = "hello"
while True:
print(var) # string variable printed on the screen
var = input("Change variable to: ") # allow the user to edit the text displayed

Countour-Integral
- 1,138
- 2
- 7
- 21
-
1
-
@wjandrea Define editing then. In SO if you click `EDIT` and wipe your post (or just enter something completely new like here) it is still considered an edit. – Countour-Integral Jan 16 '21 at 21:52
-
1Sure, but that's not what OP wants. Say I'm using OP's app and I write a new note: `Buy 12 eggs`. Later I decide I actually want to buy 18 eggs, so I open the app again, and tell it to edit my existing note. OP wants it so that the note gets printed, and I can just change the `2` into an `8`. The way you're doing it, I would have to write the whole thing again: `Buy 18 eggs`. – wjandrea Jan 16 '21 at 21:59
-
@wjandrea **so I open the app again** this means that file operations are required because temporary memory is lost when the script ends (not mentioned in the answer). **tell it to edit my existing note** that's what it is doing you are telling it what to edit. **OP wants it so that the note gets printed** that's exactly what happens it gets printed you can just change it to an 8. **The way you're doing it, I would have to write the whole thing again, Buy 18 eggs.** ok and? You are still editing the value of `var`. The question would then have to be **How to interact with text in terminal**. – Countour-Integral Jan 16 '21 at 22:04