Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Python idiom for creating dot folders in home directory? [closed]

Tags:

python

I was wondering if there's an idiom for creating dot folders and files for saving config files in all operating systems using Python.

like image 958
UXkQEZ7 Avatar asked Nov 28 '13 08:11

UXkQEZ7


1 Answers

You can get user folder with os.path.expanduser:

on Win

>>> import os, os.path
>>> os.path.expanduser('~')
'C:\\Documents and Settings\\alko'

on *nix

>>> os.path.expanduser('~')
'/home/alko'

And create dotted folder with os.mkdir (works on both):

>>> hd = os.path.expanduser('~')
>>> os.mkdir(os.path.join(hd, '.my-config'))
like image 187
alko Avatar answered Oct 17 '22 18:10

alko