You need to use os.path.expanduser and open for writing with w:
import os
with open(os.path.expanduser("~/.boto"),"w") as f:
f.write("test")
os.path.expanduser (path)
On Unix and Windows, return an argument with the original component ~ or ~ of the user replaced by that user's home directory.
Unix ~ HOME, ; pwd. ~ .
Windows, HOME USERPROFILE , , HOMEPATH HOMEDRIVE. ~ , .
, .
In [17]: open("~/foo.py")
IOError Traceback (most recent call last)
<ipython-input-17-e9eb7789ac68> in <module>()
IOError: [Errno 2] No such file or directory: '~/foo.py'
In [18]: open(os.path.expanduser("~/foo.py"))
Out[18]: <open file '/home/padraic/foo.py', mode 'r' at 0x7f452d16e4b0>
, , w, f, , r+ a.
, w , , a