Re: Best practice for config files?

Liste des GroupesRevenir à cl python 
Sujet : Re: Best practice for config files?
De : jason_hindle (at) *nospam* yahoo.com (Jason H)
Groupes : comp.lang.python
Date : 24. May 2025, 12:46:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <100sbih$mdvl$1@dont-email.me>
References : 1
User-Agent : PhoNews/3.13.3 (Android/15)
On 22/05/2025 20:59, Michael F. Stemper wrote:
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.
So, I use an environment variable because my config is shared between Python
 and Java auto test frameworks. I think keeping the config adjacent to the
 .py files is also workable because a Python program can know where it is:
from pathlib import Path
script_path = Path(__file__).resolve()
script_directory = script_path.parent
print(f"The script is located at: {script_path}")
print(f"The script is located in the directory: {script_directory}")
--
A PICKER OF UNCONSIDERED TRIFLES

Date Sujet#  Auteur
22 May 25 * Best practice for config files?11Michael F. Stemper
22 May 25 +* Re: Best practice for config files?6Stefan Ram
22 May 25 i+- Re: Best practice for config files?1Stefan Ram
23 May 25 i+* Re: Best practice for config files?3Stefan Ram
23 May 25 ii`* Re: Best practice for config files? (Posting On Python-List Prohibited)2Lawrence D'Oliveiro
24 May 25 ii `- Re: Best practice for config files? (Posting On Python-List Prohibited)1rbowman
24 May 25 i`- Re: Best practice for config files?1Michael F. Stemper
23 May 25 +* Re: Best practice for config files?2Paul Rubin
23 May 25 i`- Re: Best practice for config files? (Posting On Python-List Prohibited)1Lawrence D'Oliveiro
23 May 25 +- Re: Best practice for config files?1Chuck Rhode
24 May 25 `- Re: Best practice for config files?1Jason H

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal