如何获取运行python脚本的用户的LDAP用户名

2024-04-24 20:45:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要找到运行python(2.7)脚本的用户的LDAP用户名。命令行我可以通过输入whoami来完成,在python中,我正在寻找与pytholdap模块等效的解决方案。在


Tags: 模块命令行用户脚本解决方案ldap用户名whoami
1条回答
网友
1楼 · 发布于 2024-04-24 20:45:22

您可以使用python中getpass标准库中的getuser函数来获取当前系统用户。试试这个:

>>> from getpass import getuser
>>> getuser()
'ahmadnourallah'

相关问题 更多 >