Issue
I need to create a menu screen in Python of all the users in the system, and after the system displays the list you choose the user you want and then another menu should pop-up.
So far I have:
os.system("cut -d: -f1 /etc/passwd")
chose = str(raw_input("Select user from this list > "))
How can I make the second list appear after I choose a user?
Solution
You can use pwd
and grp
modules.
We use grp
to get user group.
import pwd, grp
user = ''
users = pwd.getpwall()
i=0
for p in users:
print str(i) + ')' + str(p[0])
i+=1
chose = int(raw_input("Select user from this list > "))
user = users[chose]
print
print '1) show user groups \n2) show user id'
print
chose = int(raw_input("Your choice > "))
if chose == 1:
print grp.getgrgid(user.pw_gid).gr_name
else:
print user.pw_uid
Answered By - Kenly