views:

28

answers:

1

How to find current user home directory on OS X?

HOME environmental variable is not always set, for example when you do not run in console (GUI apps).

For this reason I'm looking for a generic solution, one that will fall-back if os.environ['HOME'] is not set.

There is a similar question (C) but it already has an accepted solution that is invalid.

A Python solution would be preferred but other languages are welcome as long they provide a valid home or at least one location where you can write.

A: 

It looks that os.path.expanduser("~") always returns the home directory, even on Windows.

Sorin Sbarnea