The Python 3 documentation recommends using the built-in getpass.getuser() function to get the user's operating system (OS) username:
getpass.getuser()
import getpass username = getpass.getuser() print( username )
1 2 3 4 5