python - Reading a file in home directory from another directory -
python - Reading a file in home directory from another directory -
i trying read file in directory. current script in path/to/dir. however, want read file in ~/. i'm not sure how this.
i tried f = open("~/.file") getting error
ioerror: [errno 2] no such file or directory: '~/.file'
use os.path.expanduser:
import os open(os.path.expanduser('~/.file')) f: print f.read() python
Comments
Post a Comment