-1

I tried to use environment variables in order to save data. I tried to save the variables with os.environ, but in linux the variables stay empty, after executing this small script:

  import os
    os.environ['LD_LIBRARY_PATH'] = "my_path"
    exit()

dave@dave-ThinkPad-L13-Gen-2:~/PythonProjects/USAImport$ echo $LD_LIBRARY_PATH

How to set environment variables in Python?

Which is the fastest way to persist data. I just have to save a cookie.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
David
  • 2,926
  • 1
  • 27
  • 61
  • Does this answer your question? [Python: Environment Variables not updating](https://stackoverflow.com/q/60354339/6045800) TL;DR - *"The python script changes its environment. However this does not affect the environment of the parent process (The shell)"* – Tomerikoo Feb 23 '22 at 15:27
  • Does this answer your question? [Why can't environmental variables set in python persist?](https://stackoverflow.com/q/716011/6045800) – Tomerikoo Feb 23 '22 at 15:32

1 Answers1

1

Environment variables is not way to save data, but a way, how to configure your application - it survive fork and exec operation.

To easily persist your data, I would recommend you using YAML or JSON file. Here is a nice answer, which helps you to do it on few lines.

data in the answer is dictionary. If you want a shortest possible way, how to persist data, you have to premake an empty JSON file with the right structure, so you can easily read on the first run without defining it in the code.

Přemysl Šťastný
  • 1,676
  • 2
  • 18
  • 39