title: How to get path to file for python executable
body: <p>I'm trying to get path in python to open and write in text document by already exist path directory C:\ProgramData\myFolder\doc.txt, no need to create it, but make it work  with python executable on user computer. For example if this way I got folder there:</p>
  
  <pre><code>   mypath = os.path.join(os.getenv('programdata'), 'myFolder') 
  </code></pre>
  
  <p>and then if I want write:</p>
  
  <pre><code>  data = open (r'C:\ProgramData\myFolder\doc.txt', 'w')   
  </code></pre>
  
  <p>or open it:</p>
  
  <pre><code>    with open(r'C:\ProgramData\myFolder\doc.txt') as my_file:   
  </code></pre>
  
  <p>Not sure if it is correct:</p>
  
  <pre><code>   programPath = os.path.dirname(os.path.abspath(__file__))
  
     dataPath = os.path.join(programPath, r'C:\ProgramData\myFolder\doc.txt')
  </code></pre>
  
  <p>and to use it for example:</p>
  
  <pre><code>   with open(dataPath) as my_file:  
  </code></pre>