» How to find the real user home directory using python?
How to find the real user home directory using python?
|April 19, 2010
Posted by forumadmin
I see that if we change the HOME(linux) or USERPROFILE(windows) environmental variable and run a python script, it returns the new value as the user home when I tried,
Is there any way to find the real user home directory without relying on the environmental variable?. Thanx.
Here is a way to find userhome in windows by reading in the registry,
One way to find windows home using pywin32,
from win32com.shell import shell,shellcon
home = shell.SHGetFolderPath(0, shellcon.CSIDL_PROFILE, None, 0)
More Related Questions
- What is the Windows equivalent of pwd.getpwnam(username).pw_dir? The Python pwd module provides access to getpwnam(3) POSIX API, which can be used to get the home directory for a particular user by username, as well determining if the username is valid […]
- How do you get a directory listing sorted by creation date in python? What is the best way to get a list of all files in a directory, sorted by date [created | modified], using python, on a windows machine? Asked By - […]
- Applying and transferring all settings/binaries of one user to another user in Linux In a linux machine, we may have to compile our programs with respect to that linux machine.
Now, if we already have some other users (not root. A typical user.) who have already compiled […]
- How to get the home directory in Python? I need to get the location of the home directory of the current logged-on user. Currently, I've been using the following on Linux:
However, this does not work on […]
- meaning of tilde in linux bash (not home directory) First off, I know that ~/ is the home directory. CDing to ~ or ~/ takes me to the home directory.
However, cd ~X takes me to a special place, where X seems to be anything.
In bash, if I […]
- CherryPy interferes with Twisted shutting down on Windows I've got an application that runs Twisted by starting the reactor with reactor.run() in my main thread after starting some other threads, including the CherryPy web server. Here's a […]
- How do i get the user name in a Makefile? I'm making a simple game for Ubuntu and to update the highscore list, it needs a single file at runtime, called 'highscores.bin'.
I wish to put this file […]
- How can I create directory tree in C++/Linux? I want an easy way to create multiple directories in C++/Linux.
For example I want to save a file lola.file in the directory:
but if the directories are not there I want […]
- How to import a Python class that is in a directory above? I want to inherit from a class in a file that lies in a directory above the current one.
Is it possible to relatively import that file? Asked By - […]
- Calculating a directory size using Python? Before i re-invent this particular wheel, has anybody got a nice routine for calculating the size of a directory using Python? It would be very nice if the routine would format the size […]