Mendapatkan Info User (sederhana) Menggunakan Regex Pada Python

#!/usr/bin/python

import os, re

osenv = str(os.environ)
usrpat = re.compile(' 'USER': '(.*?)'')
homepat = re.compile(' 'HOME': '(.*?)'')

usrp = usrpat.findall(osenv)
hmrp = homepat.findall(osenv)

print 'USERNAME :' + usrp[0]
print 'HOME :' + hmrp[0]

in action:

Leave a Reply

Your email address will not be published. Required fields are marked *