SyntaxFix
Write A Post
Hire A Developer
Questions
Combined pwd and getpass approach, based on other answers:
pwd
getpass
try: import pwd except ImportError: import getpass pwd = None def current_user(): if pwd: return pwd.getpwuid(os.geteuid()).pw_name else: return getpass.getuser()