Python knowledge - gets the current system host name, user name, user directory.

Code Example:

import socket, getpass, os

# Get the current system hostname 
host_name = socket.gethostname ()
 # Get the current system user name 
USER_NAME = getpass.getuser ()
 # Get the current system user directory 
USER_HOME = os.path.expanduser ( ' ~ ' )

Print ( ' host name -> S% ' % host_name)
 Print ( ' User name -> S% ' % USER_NAME)
 Print ( ' User Directory -> S% ' % USER_HOME)

operation result:

Guess you like

Origin www.cnblogs.com/Python-XiaCaiP/p/11880736.html