TheRealTengri
TheRealTengri

Reputation: 1361

How can I get the user's username?

I know that I can do getpass.getuser() but that shows the user's name, not their account logon username and I want their account logon username

Upvotes: 1

Views: 564

Answers (2)

Georgina Skibinski
Georgina Skibinski

Reputation: 13407

Try this one:

For Unix

import os
import pwd

pwd.getpwduid(os.getuid())[0]

For Windows

import os

os.getlogin()

Upvotes: 1

Haili Sun
Haili Sun

Reputation: 849

No permission to edit. should be pwd.getpwuid(os.getuid())[0]

Upvotes: 0

Related Questions