My messy solution:
I am a beginning python programmer and because of my lack of advanced knowledge, I often use primitive tools to finish my advanced projects. Currently I am trying to exchange data between programs at runtime. I have tried writing and reading text files. Each program has a separate write-only text file in order to avoid two programs writing to a file at the same time.
In order to collect all the data into a single file, I have written a separate program to read the write-only text files and consolidate all the data into a single file. All programs then have access to variables from all other programs in this one file.
My request for an easier solution:
Even though the above solution works well, I am trying to find a more elegant way to share variables among Python programs. Can you tell me if there is a better way to do this in Python?
Thank you so much.
Memcached is more or less designed for what you describe, since a variable is as volatile as memory.
Redis is another good option, with some similarities to memcached, but the option to make the data persistent.
All the other direct-sharing options I could think of fall directly into the category of database (whether SQL or not), except for using flat files, which is what you’re doing now.
Finally, you could refactor the programs so that instead of sharing values directly, they provide services to one another whereby they can trade information when they need it. This may increase overhead and complexity in some cases, but eliminates the need to validate the cache of variable values if they ever change.