當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。