title: How to open a file only using its extension?
body: <p>I have a Python script which opens a specific text file located in a <strong>specific directory</strong> (<em>working directory</em>) and perform some actions.</p>
  
  <p>(Assume that if there is a text file in the directory then it will always be no more than one such <code>.txt</code> file)</p>
  
  <pre><code>with open('TextFileName.txt', 'r') as f:
      for line in f:
          # perform some string manipulation and calculations
  
      # write some results to a different text file
      with open('results.txt', 'a') as r:
          r.write(someResults)
  </code></pre>
  
  <p>My question is how I can have the script <strong>locate the text (.txt) file in the directory and open it without explicitly providing its name</strong> (i.e. without giving the 'TextFileName.txt'). So, <em>no arguments</em> for which text file to open would be required for this script to run.</p>
  
  <p>Is there a way to achieve this in Python?</p>