如何在Python中获取用户名?
问题描述:
可能重复:
Is there a portable way to get the current username in Python?如何在Python中获取用户名?
我怎样才能获得通过正在执行给定的脚本的帐户的用户名?
答
import getpass
print getpass.getuser()
如果我在* nix平台上切换用户,但getpass解决方案正常工作,则“os.getlong()”无法正常工作,谢谢。 – mxi1 2013-12-10 10:24:14