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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。