A
A
Andrey Prenrek2021-03-08 13:24:55
Python
Andrey Prenrek, 2021-03-08 13:24:55

How to add an entry to array[] so that it is saved?

I want to write data to an array "[]" which is in another file, but when I add data, the data is not saved.

import podop as pod
pod.n.append(4)
print(pod.n)

If you immediately output, it will show what is in the array "4", and then it shows without the added number "4"
How to make it save what it added?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-03-08
@phaggi

1. [] is not an array. And not an array, in general.
This is a list - a structure of sequentially arranged elements. Subsequence.
2. It is initialized every time the file is executed, created in memory and exists in memory. You start again - it is re-created.
3. The most direct and easiest way to save is to save a Python object (and a list is an object) to an external file using the pickle function .
4. You can also save in JSON, this is a more portable and versatile way. Google it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question