how to get linux username in a python program
This question already has an answer here:
Could os.getlogin() be what you are looking for? (https://docs.python.org/3/library/os.html#os.getlogin)
>>> import os
>>> os.getlogin()
'msurrow'
>>>
Or maybe getpass.getuser() (https://docs.python.org/3.1/library/getpass.html)
>>> import getpass
>>> getpass.getuser()
'msurrow'
>>>
There is a difference between who the logged in user is, and 'who' the python process is running as. Jeff explains more in his answer here
链接地址: http://www.djcxy.com/p/79422.html上一篇: 从Python脚本中获取用户