title: How to read home directory in Python
body: <p>I'm trying to write a python script that will copy some files into certain directories and then add a source to my <code>.bash_profile</code>.  I am having some issues even getting this script off the ground.  I am currently trying to just check if there is a <code>.bash_profile</code> and if so read the contents</p>
  
  <pre><code>import os.path
  
  def main():
      file_path = '~/.bash_profile'
      file_exists = os.path.isfile(file_path)
  
      if file_exists:
          print('file exists')
          f = open(file_path, "r")
          if f.mode == "r":
              contents = f.read()
              print(contents)
      else:
          print('file does not exist')
  
  if __name__== "__main__":
      main()
  </code></pre>
  
  <p>if I take my code out of the if statement I receive this error </p>
  
  <pre><code>Traceback (most recent call last):
    File "bash_install.py", line 9, in &lt;module&gt;
      main()
    File "bash_install.py", line 3, in main
      f = open('~/.bash_profile', "r")
  IOError: [Errno 2] No such file or directory: '~/.bash_profile'
  </code></pre>
  
  <p>I can't seem to find any information on how to read into the home <code>~</code> directory or is this an issue with <code>.bash_profile</code> being a hidden file? Any direction would be much appreciated</p>