how to find current working user

Tim Chase python.list at tim.thechases.com
Mon Feb 11 14:36:24 EST 2008


> Can anyone tell me how to find current working user in windows?

The below should be fairly cross-platform:

    >>> import getpass
    >>> whoami = getpass.getuser()
    >>> print whoami
W: tchase
L: tim

("W:" is the result on my windows box, "L:" is the result on my 
Linux box) which can be used in concert with

    >>> import user
    >>> print user.home
W: C:\Documents and Settings\tchase
L: /home/tim

or

    >>> import os
    >>> os.expanduser('~/Desktop')
W: C:\Documents and Settings\tchase/Desktop
L: /home/tim/Desktop

in case you need either of them.

-tkc






More information about the Python-list mailing list