» What is the Windows equivalent of pwd.getpwnam(username).pw_dir?
What is the Windows equivalent of pwd.getpwnam(username).pw_dir?
|July 22, 2010
Posted by forumadmin
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 at all.
pwd.getpwnam will raise an exception if called with a non-existent username.
At first it seems like the same result can be achieved in a cross-platform manner via
os.path.expanduser('~username'). However, it appears that with Python 2.6 on Windows XP this won’t actually produce a failure for a non-existent username. Furthermore, on Python 2.5 on Windows XP, it seems to fail even for valid users.
Can this information be obtained reliably on Windows? How?
More Related Questions
- How to find the real user home directory using python? 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 […]
- 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 […]
- 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 […]
- Open Explorer on a file In Python, how to jump to file in Windows Explorer (like in Winamp)? I found a solution for jumping to folders:
but I […]
- Drag and drop onto Python script in Windows Explorer I would like to drag and drop my data file onto a Python script and have it process the file and generate output. The Python script accepts the name of the data file as a command-line […]
- Can I install Python windows packages into virtualenvs? Virtualenv is great: it lets me keep a number of distinct Python installations so that different projects' dependencies aren't all thrown together into a common pile.
But if I want to […]
- Windows is not passing command line arguments to Python programs executed from the shell I'm having trouble getting command line arguments passed to Python programs if I try to execute them directly as executable commands from a Windows command shell. For example, if I have […]
- How to set up a simple web server(Windowws XP Pro) As a heads up, I have some experience programming on Windows and other devices, but I have almost zero experience doing web anything, so I'm sure this is simple/easy to find online and I […]
- Building lxml for Python 2.7 on Windows I am trying to build lxml for Python 2.7 on Windows 64 bit machine. I couldn't find lxml egg for Python 2.7 version. So I am compiling it from sources. I am following instructions on this […]