# shell
last | cut -d ' ' -f 1 | sort -u
#python
from subprocess import Popen,PIPE p1 = Popen('last',shell=True,stdout=PIPE) p2 = Popen('cut -d ' ' -f 1,shell=True,stdin=p1.stdout,stdout=PIPE) p3 = Popen('sort -u',shell=True,stdin=p2.stdout,stdout=PIPE) >>print p3.stdout.read()