Python内置模块:getpass

import getpass

user = getpass.getuser()