Question

Using this general structure:

setup.py
/package
    __init__.py
    project.py
    /data
        client.log

I have a script that saves a list of names to client.log, so I don't have to reinitialize that list each time I need access to it or run the module. Before I set up this structure with pkg_resources, I used open('.../data/client.log', 'w') to update the log with explicit paths, but this doesn't work anymore.

Is there any way to edit data files within modules? Or is there a better way to save this list?

Was it helpful?

Solution

No, pkg_resources are for reading resources within a package. You can't use it to write log files, because it's the wrong place for log files. Your package directory should typically not be writeable by the user that loads the library. Also, your package may in fact be inside a ZIP-file.

You should instead store the logs in a log directory. Where to put that depends on a lot of things, the biggest issue is your operating system but also if it's system software or user software.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top