Computer Science Atlas
Snippets

Python 3: User's OS Username

February 18, 2021
 

The Python 3 documentation recommends using the built-in getpass.getuser() function to get the user's operating system (OS) username:

import getpass

username = getpass.getuser()

print( username )
1
2
3
4
5
import getpass

username = getpass.getuser()

print( username )

References