Re: Searching for a file

2025-05-23 Thread Mats Wichmann

On 5/22/25 21:04, Rob Cliffe via Python-list wrote:
It occurs to me that it might be useful if Python provided a function to 
search for a file with a given name in various directories (much as the 
import.import_lib function searches for a module in the directories in 
sys.path).

This function would perhaps be best placed in the os.path or os modules.
To start the ball rolling, I offer this version:

consider: os.walk, glob.glob, Path.glob


--
https://mail.python.org/mailman3//lists/python-list.python.org


Re: Best practice for config files?

2025-05-23 Thread c . buhtz

Hello Michael,

thank you for your important question.

On GNU/Linux (and maybe for POSIX?) systems there is a standard about 
it.




Look for $XDG_CONFIG_HOME.

To drive it further, you might distinguish between config data (related 
and readable to users) and state data (e.g. size, position of windows, 
...). The later is often also stored in a config file, which is not a 
good idea. For state data you should use $XDG_STATE_HOME.


If the system does not provide the environment variable use a default 
value.


See one example [1] for a config path or for a state file [2].

Feel free to ask back if you have further questions or suggestions.

Regards,
Christian Buhtz

[1] -- 

[2] -- 


--
https://mail.python.org/mailman3//lists/python-list.python.org


Re: Searching for a file

2025-05-23 Thread Rob Cliffe via Python-list



On 23/05/2025 18:55, Mats Wichmann wrote:

On 5/22/25 21:04, Rob Cliffe via Python-list wrote:
It occurs to me that it might be useful if Python provided a function 
to search for a file with a given name in various directories (much 
as the import.import_lib function searches for a module in the 
directories in sys.path).

This function would perhaps be best placed in the os.path or os modules.
To start the ball rolling, I offer this version:

consider: os.walk, glob.glob, Path.glob



I have.  None of these are appropriate.
os.walk iterates *recursively* over a *single* directory and its 
subdirectories.
pathlib.Path.glob so far as I can make out (I have never used pathlib) 
does much the same.
glob.glob (so far as I can make out) does a *wildcard* search for 
directories matching a *single* pattern.
My suggestion needs a *non-recursive* search for a *file* in a *list* of 
*non-wildcarded* directories.

Best wishes
Rob Cliffe
--
https://mail.python.org/mailman3//lists/python-list.python.org


Re: Best practice for config files? (Posting On Python-List Prohibited)

2025-05-23 Thread rbowman
On Fri, 23 May 2025 22:22:36 - (UTC), Lawrence D'Oliveiro wrote:

> 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.

Good luck with that. I've got 48 directories ranging from .arduino15 
to .vscode. Then there are the 58 directories in .config.

-- 
https://mail.python.org/mailman3//lists/python-list.python.org


Re: Best practice for config files?

2025-05-23 Thread Chuck Rhode
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Thu, 22 May 2025 14:59:28 -0500
"Michael F. Stemper"  wrote:

> Is requiring the program to be executed in the directory containing
> the configuration file considered acceptable practice?

Freedesktop.org proposes a specification for where such things ought
to be located:

+ https://specifications.freedesktop.org/basedir-spec/latest/

Here's how I do it:

> def get_xdg_config_home():
> 
> """The configuration directory.
> 
> Normally $HOME/.config. 
> 
> """
> 
> result = pathlib.Path.home() / ".config"
> return result

- -- 
.. Be Seeing You,
.. Chuck Rhode, Sheboygan, WI, USA
.. Weather:  https://LacusVeris.com/Wx
.. 47° — Wind NNW at 12 mph. Sky clear.
-BEGIN PGP SIGNATURE-

iF0EARECAB0WIQT+MY/5I/LMPSswTbVg2/xipKOWUgUCaDB5oAAKCRBg2/xipKOW
Ukg/AJ9cWxtykecg31HvVrCz+GhWPOn+gQCePacKiSXFlRdkEeyrzksobcbTCFw=
=OzzD
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman3//lists/python-list.python.org