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

by
Jeremy Canfield |
Updated: April 01 2024
| 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