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

相關用法
- Python os.dup()用法及代碼示例
- Python next()用法及代碼示例
- Python set()用法及代碼示例
- Python hasattr()用法及代碼示例
- Python PIL putdata()用法及代碼示例
- Python PIL getcolors()用法及代碼示例
- Python PIL tobytes()用法及代碼示例
- Python PIL getpalette()用法及代碼示例
- Python os.get_blocking()用法及代碼示例
- Python Tensorflow cos()用法及代碼示例
- Python sympy.crt()用法及代碼示例
- Python sympy.nT()用法及代碼示例
- Python PIL putalpha()用法及代碼示例
注:本文由純淨天空篩選整理自ihritik大神的英文原創作品 Python | os.getlogin() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
