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

Popular posts from this blog

javascript - THREE.js reposition vertices for RingGeometry -

javascript - I need to update the text of a paragraph by inline edit -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -