title: How to read a file that was just created by a function in python
body: <p>I am getting blank line when I try to read the file that was just created by function above. When I run the same code in different file it is running just file. I see that file has been closed. But when I try to open and print. I am getting blank line.</p>
  
  <p>I have copied the same code which I am trying to read to a different test file and run the code. I am read the file and print the lines and close the file. </p>
  
  <pre class="lang-py prettyprint-override"><code>def running_symm_list_cmd():
      try:
  
          path_to_output_file = "symm_list_out.txt"
          myoutput = open(path_to_output_file, 'w')
          symm_list = "sudo symcfg list"
          Popen([symm_list], shell=True, stdout=myoutput, stderr=myoutput, universal_newlines=True)
  
      except OSError or ValueError as error_str:
          print(error_str)
          os.system(exit(2))
      finally:
          myoutput.close()
          print("checking if file is closed or not {}".format(myoutput.closed))
  
  
  def getting_symm_list():
  
      try:
          print("INSIDE getting_symm_list TRY  function")
          symm_list = {}
          path = "/users/pjinde/scripts/symm_list_out.txt"
          symm_list_file = open(path, 'r')
          print("file mode is {m} and file name is {n}".format(m=symm_list_file.mode, n=symm_list_file.name))
          for line in symm_list_file.readlines():
              #print(line)
              symm_ids = re.search(r'(000197\d+)\s+\w+.*', line, re.M | re.I)
              if symm_ids:
                  symm_list[symm_ids.group(1)] = None
                  #print("Symmetrix id is {}".format(symm_ids.group(1)))
  
          for ids in symm_list.keys():
              print("symmetrix_id are {}".format(ids))
  
      except OSError as err:
          print("unable to get symm list due to error {}".format(err))
      finally:
          symm_list_file.close()
      return symm_list
  </code></pre>
  
  <p>I am expecting below output. Which tell that I was able to create a dictionary symm_list.</p>
  
  <pre><code>INSIDE getting_symm_list TRY  function
  file mode is r and file name is /users/abcd/efcg/symm_list_out.txt
  symmetrix_id are 00019780aaaa
  symmetrix_id are 00019780aabc
  symmetrix_id are 00019780aadd
  symmetrix_id are 00019780aaee
  symmetrix_id are 00019780aaff
  symmetrix_id are 00019780aaeg
  symmetrix_id are 00019790bbbb
  </code></pre>
  
  <p>Any help is greatly appreciated !!. thanks.</p>