Should I specify the location of the config file with a command-line
option, or is requiring the program to be executed in the directory >containing the configuration file considered acceptable practice?
On Linux:
~/.config/YourAppName
Should I specify the location of the config file with a command-line
option, or is requiring the program to be executed in the directory containing the configuration file considered acceptable practice?
"Michael F. Stemper" <michael.stemper@gmail.com> writes:
Should I specify the location of the config file with a command-line
option, or is requiring the program to be executed in the directory
containing the configuration file considered acceptable practice?
You can also use an environment variable.
Is requiring the program to be executed in the directory containing
the configuration file considered acceptable practice?
def get_xdg_config_home():
"""The configuration directory.
Normally $HOME/.config.
"""
result = pathlib.Path.home() / ".config"
return result
- searching a sequence of locations for your config file
Coincidentally, I just read:
|When IDLE first starts, it attempts to read user |configuration files
in ~/.idlerc/ (~ is one's home |directory).
On 23 May 2025 19:18:23 GMT, Stefan Ram wrote:
Coincidentally, I just read:
|When IDLE first starts, it attempts to read user |configuration files
in ~/.idlerc/ (~ is one's home |directory).
Apps should be abiding by the XDG spec nowadays, and stop cluttering up users’ home directories.
I recently wrote a program to do some record-keeping for me. I found
myself hard-coding a bunch of different values into it. This didn't
seem right, so I made my first use of configparser.ConfigParser().
Created the configuration file and everything is working fine.
However, I wrote it based on the assumption that the program is
running in the directory where the config file is stored, and has
a specific name. I started having some second thoughts here.
I thought about putting the location of the configuration file in
the configuration file, but that seemed like a non-starter.[1]
Should I specify the location of the config file with a command-line
option, or is requiring the program to be executed in the directory >containing the configuration file considered acceptable practice?
[1] See Tegan Jovanka in _Castrovalva_ for more on this idea.
"Michael F. Stemper" <michael.stemper@gmail.com> wrote or quoted:
Should I specify the location of the config file with a command-line
option, or is requiring the program to be executed in the directory
containing the configuration file considered acceptable practice?
It was me who digged out this "platformdirs" "user_config_dir"
API using a source code search on my harddisk without any help.
But then I asked my buddy, the chatbot, to explain how to
use it, which I include here, followed by some more words
of my own at the end. Chatbot:
On Linux:
~/.config/YourAppName
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,064 |
Nodes: | 10 (0 / 10) |
Uptime: | 150:05:57 |
Calls: | 13,691 |
Calls today: | 1 |
Files: | 186,936 |
D/L today: |
438 files (115M bytes) |
Messages: | 2,410,973 |