Priyanshu
Priyanshu

Reputation: 127

How do I restrict files (SQLite3 DB, etc.) from being deleted until the Python program is running?

I am working on a small python3 project which is a TKinter GUI program, how I can restrict users from deleting the associated files like sqlite3 DB, templates, html etc. until the python script is running. I tried some solution of locking the file into read only which restricts users to delete files but same time it became Un useful for my python script. Is there any way i can keep the file read/write for python script but read only for user who is using the program so files cannot be removed.

Upvotes: 1

Views: 108

Answers (1)

Kalosst0
Kalosst0

Reputation: 38

If you open files with with open(), they will be marked as "used" by Python, and you can't delete them.

Example:

import asyncio

async def main():
    with open(r".\fox.txt"):
        await asyncio.sleep(1000)

if __name__ == "__main__":
    asyncio.run(main())

Upvotes: 0

Related Questions