osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

preferences file


Dave,

On 25/01/19 8:42 AM, Dave wrote:
> I'm doing a small application and want to add user preferences.? Did 
> some googling to see if there are standard Python ways/tools, but it 
> seems not so much.? My specific questions are:
> 
> 1. Best practices for a user preference file/system?
 > [edited]
 > Would like to find a Python library that handles all of this, but so 
far...

=Had a similar need. Also looked around, but failed. Will be interested 
in any discussion that follows...


> 2. File format favored and why - ini, JSON, etc?

=Am no great fan of .ini (a) where it is most used, ie cynicism and 
bias; and (b) and because it is too "flat".

=Initially thought to use .conf, comforted by frequent use on Linux 
servers, but similar criticism.

(at this point the PSL's configparser bows out)

=Looked at .JSON and liked the syntactic similarities to Python.

(utility available in PSL)

=Settled on .YAML, mostly because not very different to .JSON yet has 
specific, applicable design philosophy.

(IIRC picked this up through pip3)

=Ended-up coding my own little utility to call from any/every 
application; based on import yaml. Will be interested to see if someone 
suggests something I missed back-then...


=Have been gradually adding further facilities, eg commandLN overrides. 
Also, been wondering about its applicability to my web work - 
particularly when it comes to separating versions, eg "live" from (user 
acceptance) "test"...

=Once done, I've noticed myself coding fewer global constants, instead 
putting them into the .yaml configuration file. Of course, this adds a 
point-of-failure - particularly if the user has access/editing rights on 
the file (but with great power, comes ...!)


> 3. File location?? I'm using Ubuntu and I believe that the correct 
> location would be home/.config/<app-name> .? What about Mac and Windows?

=Makes good sense, but ultimately depends upon usage/the application/how 
it is to be delivered to the users (and possibly more). Obviously if the 
user is not on that machine, or you run on behalf of several users that 
won't work (perhaps implement separate .../userNM/ sub-directories and 
use such for both config input and any output files/reports).

=Again, will be interested to see others' ideas...

(this smart-alec locates his windows in the wall, and keeps his mac in 
the cupboard/closet)

-- 
Regards =dn