I'm running a script that is grabbing data from a .env file. I am trying to update the .env variable in the middle of the script and then use that new value. It's an encryption script, so I need to have the .env value to decrypt, update the value, and then use the new value to encrypt it again. What's happening instead is it is decrypting, reencrypting, and then updating. It seems like that's just how .env files work, but I was hoping there was a way to make the variable update mid-script. Here's the code that I'm running:
def changeSecret(slices, envvars, num):
key = sign(slices) #function I wrote decrypting several slices of data and putting them together
dotenv_file = dotenv.find_dotenv()
dotenv.load_dotenv(dotenv_file)
dotenv.set_key(dotenv_file, 'secret', str(num)) #this ends up updating the .env variable only when the program finishes
slices = encrypt(key) #the 'encrypt' function uses os.getenv('secret'), so I want it to have updated already
updateenv(slices, envvars) #this updates other variables.