社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Michael Kropat

Michael Kropat 最近创建的主题
Michael Kropat 最近回复了

通过Windows API可以在Windows上获得当前用户名,不过通过ctypes FFI调用有点麻烦( GetCurrentProcess → OpenProcessToken → GetTokenInformation → LookupAccountSid ).

我写了一个小模块,可以直接从Python中实现这一点, getuser.py . 用法:

import getuser
print(getuser.lookup_username())

它可以在Windows和*nix上运行(后者使用 pwd 其他答案中描述的模块)。