10 examples of 'python get username' in Python

Every line of 'python get username' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
78def getUserName():
79 return pwd.getpwuid(os.getuid()).pw_name
30def get_username(user):
31 try:
32 return user.get_username()
33 except AttributeError:
34 return user.username
749def get_username(uid):
750 """Get linux username from uid
751 """
752 return pwd.getpwuid(uid).pw_name
44def get_login():
45 """Get current effective user name"""
46 return pwd.getpwuid(os.getuid()).pw_name
28def getUsername():
29 """Returns the currently logged-in username.
30
31 Returns:
32 str: The current username.
33 """
34 import getpass
35 return getpass.getuser()
65def get_user(config):
66 try:
67 server = config['metadb']['server']
68 username = '@'.join([config['metadb']['db_username'], server])
69 except KeyError:
70 username = config['metadb']['db_username']
71 return username
90def getuser():
91 """Get the username from the environment or password database.
92
93 First try various environment variables, then the password
94 database. This works on Windows as long as USERNAME is set.
95
96 """
97
98 import os
99
100 for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
101 user = os.environ.get(name)
102 if user:
103 return user
104
105 # If this fails, the exception will "explain" why
106 import pwd
107 return pwd.getpwuid(os.getuid())[0]
46def get_user():
47 if sys.platform == 'win32':
48 return os.environ['USERNAME']
49 else:
50 import pwd
51 return pwd.getpwuid(os.getuid())[0]
29def _get_user():
30 """Get the current computer username."""
31 try:
32 return getpass.getuser()
33 except ImportError:
34 return _DEFAULT_USER
31def get_username(prompt="Enter username: ", defaultUser=None):
32 """Prompt for a username, allowing pre-populated *defaultUser*."""
33 if cfg.opts.neverPromptCreds:
34 quit_login_failed()
35 user = raw_input(prompt)
36 while not len(user):
37 if defaultUser:
38 user = defaultUser
39 else:
40 user = raw_input(" You must enter a username: ")
41 return user

Related snippets