2

I'm creating a simple Python CLI tool, which lets the user add and delete tasks (the classic Todo app). This is just for my own use, but I want to get into the best practices of creating such applications. The data will be stored in a simple text file.

Main question: Where should I store the data file? After doing some reading, I'm inclined to create a new folder in /var/lib and keep the data.txt file in that directory. Are there any drawbacks to that option?

Follow up question: Since, by default, only root has access to /var, do I need to change the permissions for the whole /var directory in order to read and write to the data file?

Community
  • 1
  • 1

1 Answers1

5

User data should be store in the user's home directory. You could use..

Mac OS X

/Users/joe/.myclitool/data.txt

GNU/Linux

/home/joe/.myclitool/data.txt

In Python this can be done with:

import os
import os.path

p = os.path.join(os.getenv("HOME"), ".myclitool", "data.txt")
Neuron
  • 5,141
  • 5
  • 38
  • 59
  • I was just about to ask how the application would know the identity of the current user, but your edit clarified things. Thank you! –  Jul 07 '14 at 10:46