Advertisement
Python253

whoami

May 24th, 2024
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: whoami.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    - This script retrieves the username of the current user on the system.
  10.    
  11. Functions:
  12.    - get_user_info(): Retrieves information about the current user on the system.
  13.  
  14. Requirements:
  15.    - Python 3.x
  16.  
  17. Usage:
  18.    - Run the script with the Python command:
  19.    
  20.              python whoami.py
  21.  
  22. Additional Notes:
  23.    - This script uses the getpass module to retrieve the current user's username.
  24.    - It is compatible with Python 3.x.
  25.    - Running the script without any arguments will print the current user's username.
  26. """
  27.  
  28. import getpass
  29.  
  30. def get_user_info():
  31.     """
  32.    Retrieve information about the current user on the system.
  33.  
  34.    Returns:
  35.        dict: A dictionary containing the following user information:
  36.            - 'Username': The current user's username.
  37.    """
  38.     # Get current user's username
  39.     username = getpass.getuser()
  40.  
  41.     return {
  42.         "Username": username
  43.     }
  44.  
  45. if __name__ == "__main__":
  46.     user_info = get_user_info()
  47.     for key, value in user_info.items():
  48.         print(f"{key}: {value}")
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement