title: How to use the same line of code in all functions?
body: <p>I am newbie in Python. 
  I wonder if it is possible that all functions inherit the same line of code? </p>
  
  <p><code>with open(filename, 'r') as f:</code> as this line of code is the same in all three functions. Is it possible to inherit the code without using classes?</p>
  
  <p>I tried to find the answer on stackoverflow and python documentation, but with no luck.</p>
  
  <pre><code>def word_count(filename):
      with open(filename, 'r') as f:
          return len(f.read().split())
  
  
  def line_count(filename):
      with open(filename, 'r') as f:
          return len(f.read().splitlines())
  
  
  def character_count(filename):
      with open(filename, 'r') as f:
          return len(f.read())
  </code></pre>