Bootstrap FreeKB - Python (Scripting) - Return username using getpass getuser (whoami)
Python (Scripting) - Return username using getpass getuser (whoami)

Updated:   |  Python (Scripting) articles

getpass.getuser() can be used to get the username of the user running a Python script.

#!/usr/bin/python3
import getpass
print(f"whoami = {getpass.getuser()}")

 

Which should return something like this.

whoami = john.doe

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 56602c in the box below so that we can be sure you are a human.