0

I'm creating a script that can be activated by multiple users and act upon files in their home directory.

Currently, I have the code running with a static path, but I really need to set it up to be dynamic. I don't know if it's easier to harvest the current user id or to harvest the current user's home directory... either works for me really, I'm just not sure where to start.

Any suggestions are welcome.

Software Versions:

 Python 3.6.1 (default, Jul 10 2017, 18:23:06)
 [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
nuprap
  • 385
  • 5
  • 22
  • What you want is easily done with the `os` module. In particular, look at `os.getuid()` and `os.getcwd()`. – cs95 Jul 11 '17 at 19:42

1 Answers1

1

This would give the current username:

import os
os.getusername()

To get the userid

os.getuid()

To get the home directory

from os.path import expanduser
home = expanduser("~")