Wednesday, April 27, 2011

[Level 1] How to get user home directoy in Python

#!/bin/env python
import os
print os.path.expanduser('~')
print os.path.expanduser('~stanley')
print os.environ['HOME']
./getUserHomeDirectory.py 
/home/stanley
/home/stanley
/home/stanley
Wish this helps.
regards,
Stanley Huang