title: How to make a decorator that checks if a variable exists?
body: <p>I'm trying to learn how to make my own decorators.  I don't understand how to "call" the data inside the function that is being wrapped.</p>
  
  <p>I am trying to make a really simple decorator that writes out the value of msg to a textfile.</p>
  
  <pre><code>def logging(f):  
      def decorator(args, **kwargs):    
          debug_file = "/tmp/easylog.txt"
          fh = open(debug_file, 'a')
          fh.write(f.message + "\n")
          fh.close() 
      return decorator  
  
  @logging
  def test(a,b):
      c=a+b
      message = "hello test"
      return c
  
  
  test(4,5)
  </code></pre>
  
  <p>So the part I don't understand how to do is check for message inside the decorator.</p>
  
  <p>In all the basic tutorials I've read it shows how to just take the entire return value and print it in bold or something, i'm trying to learn how to take individual values and manipulate them.</p>