Abhi Yerra

Rants of lunatic

Archive for September 2006

Get Login Name from Python

without comments

[tags]python[/tags]

I was writing a script for the OCF and I found that I needed to access the login name of the user. Thankfully Python has a builtin library to do so.

>>> import os
>>> import pwd
>>> pwd.getpwuid(os.getuid())[0]
'abhi'
>>> pwd.getpwnam('abhi')
('abhi', '********', 501, 501, 'Kesava Yerra', '/Users/abhi', '/bin/bash')

Written by abhiyerra

September 26, 2006 at 5:06 pm

Posted in all