I have this code below to store some text in a file ~/.boto that is in home directory.
But Im getting this error:
IOError: [Errno 2] No such file or
Tilde expansions doesn't work inside open(). So python won't be able to expand ~ to /home/user
A solution would be to read HOME environmental variable using os.environ
import os
home = os.environ['HOME']
file = open( home + "/.boto", "w")
file.write("test")
file.close()
OR
Using os.path.join and os.environ
>>> import os
>>> filename = ".boto"
>>> os.path.join( os.environ['HOME'], filename)
/home/user/.boto