前一段时间我编写了plx模块,以便在Unix和Windows上以可移植的方式获取用户名(除其他外): http://www.decalage.info/en/python/plx
用法:
import plx username = plx.get_username()
(在Windows上需要win32扩展)