Saving/Updating a value

I don’t know how to say this but I need to save a value inside a function, for example a number. Then incrementing by 1 each time it executes. Say it is Operation ID and it is n° 200. It executes five times and it prints 201, 202, 203, 204 and 205. What I need is that 205 is automatically set to next value in case of a future execution of the function.
Let me try to elaborate:

idOperacion = 200  # ID

for i in range(len(trx.index)): # HAS 5 ITEMS
     idOperacion = idOperacion + 1

And then it prints 201, 202, 203, 204 and 205

I want that 205 to be idOperacion the mext time I execute the script with out changing it by hand.

>Solution :

You need to save you variable within a external file.
This is a lot of ways to save and load data.

Here is a mehtod that fulfill your needs

  • loading
with open('idOperacion') as f:
    idOperacion = int(
  • saving
with open('idOperacion', 'w') as f:

Leave a Reply