Python Forum
How to put users in a dictionary?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to put users in a dictionary?
#1
How do i put my users in a dictionary, then access the key value pairs uid, name and shell?
Reply
#2
from dataclasses import dataclass


@dataclass()
class User:
    uid: str
    name: str
    shell: str


user_dict = {}
user1 = User('1', '2', '3')
user_dict[user1.uid] = user1
print(user_dict)
print(user_dict['1'].name)
print(user_dict['1'].shell)
Output:
{'1': User(uid='1', name='2', shell='3')} 2 3
Reply
#3
Thank you for the response, but i meant my the users with pwd.getpwall.
Reply
#4
Answers are limited by the quality of the question that's asked, please read the links in my signature.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020