Is there a portable way to get the current username in Python?

前端 未结 12 812
别那么骄傲
别那么骄傲 2020-11-22 03:11

Is there a portable way to get the current user\'s username in Python (i.e., one that works under both Linux and Windows, at least). It would work like os.getuid

12条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 03:48

    I wrote the plx module some time ago to get the user name in a portable way on Unix and Windows (among other things): http://www.decalage.info/en/python/plx

    Usage:

    import plx
    
    username = plx.get_username()
    

    (it requires win32 extensions on Windows)

提交回复
热议问题