10 examples of 'python get user home directory' in Python

Every line of 'python get user home directory' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
61def get_home_dir():
62 _base_dir = os.path.expanduser('~')
63 _ilms_dir = os.path.join(_base_dir, '.ilms')
64 return _ilms_dir
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

24def get_home():
25 from os.path import expanduser
26 return expanduser("~")
61def get_user_data_dir():
62 return __get_user_dir("XDG_DATA_HOME", ".local/share")
643def get_config_home():
644 """Returns the base directory relative to which user specific configuration
645 files should be stored.
646
647 :returns: Configuration base directory
648 :rtype: str
649 >>> import os; os.environ['XDG_CONFIG_HOME'] = '/tmp'
650 >>> get_config_home()
651 '/tmp'
652 """
653 return os.environ.get('XDG_CONFIG_HOME') or os.path.join(
654 os.path.expanduser('~'), '.config'
655 )
141def get_home_folder():
142 return '/home/{0}'.format(get_user())
24def getHomeDir():
25 # return os.environ['HOME']
26 return ensureFinalSlash(expanduser("~"))
11def get_data_home(data_home=None):
12 """Get the home data directory.
13
14 By default the data dir is set to a folder named 'astroML_data'
15 in the user home folder.
16
17 Alternatively, it can be set by the 'ASTROML_DATA' environment
18 variable or programatically by giving an explit folder path. The
19 '~' symbol is expanded to the user home folder.
20
21 If the folder does not already exist, it is automatically created.
22 """
23 import os
24 if data_home is None:
25 data_home = os.environ.get('ASTROML_DATA',
26 os.path.join('~', 'astroML_data'))
27 data_home = os.path.expanduser(data_home)
28 if not os.path.exists(data_home):
29 os.makedirs(data_home)
30 return data_home
245def _getuserbase():
246 env_base = os.environ.get("PYTHONUSERBASE", None)
247 if env_base:
248 return env_base
249
250 def joinuser(*args):
251 return os.path.expanduser(os.path.join(*args))
252
253 if os.name == "nt":
254 base = os.environ.get("APPDATA") or "~"
255 return joinuser(base, "Python")
256
257 if sys.platform == "darwin" and sys._framework:
258 return joinuser("~", "Library", sys._framework,
259 "%d.%d" % sys.version_info[:2])
260
261 return joinuser("~", ".local")
121def _get_home(self):
122 # This function should be robust
123 # First, let us try with expanduser
124 try:
125 homedir = os.path.expanduser("~")
126 except ImportError:
127 # This may happen.
128 pass
129 else:
130 if os.path.isdir(homedir):
131 return homedir
132 # Then, with getenv
133 for this in ('HOME', 'USERPROFILE', 'TMP'):
134 # getenv is same as os.environ.get
135 homedir = os.environ.get(this)
136 if homedir is not None and os.path.isdir(homedir):
137 return homedir
138 return None
24def _get_default_directory():
25 """Returns the default directory for the Store. This is intentionally
26 underscored to indicate that `Store.get_default_directory` is the intended
27 way to get this information. This is also done so
28 `Store.get_default_directory` can be mocked in tests and
29 `_get_default_directory` can be tested.
30 """
31 return os.environ.get('PRE_COMMIT_HOME') or os.path.join(
32 os.environ.get('XDG_CACHE_HOME') or os.path.expanduser('~/.cache'),
33 'pre-commit',
34 )

Related snippets