[Tutor] edit JSON or file in real time

Julius Hamilton juliushamilton100 at gmail.com
Wed Sep 29 11:59:52 EDT 2021


Hey,

I would like to edit some data - essentially, a 2d array, a spreadsheet of
rows and columns - in a live Python shell.

I can imagine preferring that the file will remain in a tab-delimited .txt
file, because it's very readable and easy to pass between different
applications and so on.

However, I also would like a smooth, convenient way to load that data into
Python in a data type easy to work with in Python, i.e. lists.

I also would like to make sure that if I edit something in that data
structure it is saved immediately to the corresponding file. I wouldn't
want to make an edit to an entry in the data in the live shell and somehow
lose my progress because it wasn't written to the file.

However, I don't want to explicitly execute a "write list back to file"
command every time a change a value in the list.

I would rather find some simple mode or mechanism where Python knows the
list I am editing corresponds to a file, and it understands the
correspondence. I.e., list(0) is the first entry in the tab-delimited file.

Is there any way that I could edit a list's value and it would
automatically write to the file? Do I need to create my own object with its
own methods, rather than the native Python list?

Thank you,
Julius


More information about the Tutor mailing list