Oct-18-2022, 10:53 AM
(Oct-18-2022, 06:25 AM)3Pinter Wrote: My questions:
- which is the better format? I now would say json due the library style
- what if two users run (different) scripts at the same time. Could the file be 'open' thus creating an error? If so: can I catch that?
- is this saving to a network location a good approach?
- "Which is the better format?" I would not choose json because a json file is supposed to contain one object and is not fit for appending. There are ways to fiddle about with the json principle but I would not do so. I would prefer a csv file.
- Concurrency and file locking: that is an interesting question. A file object has a "closed" attribute which holds the value True or False, but I suspect this covers only the situation in one program. Not concurrent programs. You could do a test with one program opening a file for let's say one minute, and then a second program trying to open the same file. Does it produce an exception? Then you could use an try ... except construction to wait until the file is not locked anymore. If you are really concerned about this you should consider to use a database. A database will have mechanisms to handle concurrent updates. Even sqlite3 (included with Python) has these mechanisms.
- I would certainly prefer a network location.