title: Can file object called from decorator to wrapped function?
body: <p>I want to call the file object from decorator to the wrapped function . may codes as below :</p>
  <pre><code>from functools import wraps
  checkresultfile = './test.txt'
  def log_detection_res(detect_items = ''):
    def process_reminder_decorator(check_func):
        @wraps(check_func)
        def addingReminder(*args, **kwargs):
            process_begin_reminder = &quot;=&quot; * 10 + detect_items + &quot;start&quot; + &quot;=&quot; * 10
            process_stop_reminder = &quot;=&quot; * 10 + detect_items + &quot;end&quot; + &quot;=&quot; * 10
            with open(checkresultfile, 'a') as res_file:
                res_file.write(process_begin_reminder + '\n')
                check_func(*args, **kwargs)
                res_file.write(process_stop_reminder + '\n')
            return check_func(*args, **kwargs)
        return addingReminder
    return process_reminder_decorator
  
  @log_detection_res(detect_items = 'filter odd')
  def print_odd(array_a):
      for _ in array_a:
          if _ % 2 == 0:
              checkresultfile.write(_)
  
  filter_dd = print_odd([1,2,3,4,5])
  
  out_put
  
    line 21, in print_odd
      checkresultfile.write(_)
  AttributeError: 'str' object has no attribute 'write'
  
  </code></pre>
  <p>The error comes due to <code>checkresultfile</code> is a <code>str</code> not <code>file object</code>, the error parts can be fixed by as below :</p>
  <pre><code>def print_odd(array_a):
      with open (checkresultfile, 'a') as f:               
          for _ in array_a:                 
              if _ % 2 == 0:                
                  f.write(str(_))
  </code></pre>
  <p>I don't want ot use <code>with open ... as ...</code> in the wrapped function but call the  <code>res_file</code> in decorator , is that reliable in such situation ?</p>