当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python os.getlogin()用法及代码示例


Python中的OS模块提供了与操作系统进行交互的函数。操作系统属于Python的标准实用程序模块。该模块提供了使用依赖于操作系统的函数的便携式方法。

os.getlogin()Python中的方法用于获取在进程的控制终端上登录的用户的名称。

用法: os.getlogin() 

参数:不需要

返回类型:此方法返回一个字符串,该字符串表示在进程的控制终端上登录的用户的名称。

代码#1:使用os.getlogin()方法

# Python program to explain os.getlogin() method  
    
# importing os module  
import os 
  
# Get the name of the user 
# logged in on the controlling  
# terminal of the process. 
user = os.getlogin() 
  
  
# Print the name of the user 
# logged in on the controlling  
# terminal of the process. 
print(user) 
输出:
ihritik

os.getlogin() output



相关用法


注:本文由纯净天空筛选整理自ihritik大神的英文原创作品 Python | os.getlogin() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。