title: It there a way to self-initialise a function outside of a class?
body: <p>I have this piece of code that needs to run each time I execute the program (it empties a folder):</p>
  
  <pre><code>import os
  
  def ClearOutputFolder():
      ''' Clear 'Output/' directory '''
      for file in os.listdir('Output'):
          file_path = os.path.join('Output', file)
          try:
              if os.path.isfile(file_path):
                  os.unlink(file_path)
          except Exception as e:
              print(e)
  
  ClearOutputFolder()
  </code></pre>
  
  <p>I was wondering if there's a less awkward way of automatically calling a function than defining it and then calling it later.</p>
  
  <p>I've tried to put an <code>__init__</code> outside of a class, just to see, but as expected it acted like a normal function and needed to be called.</p>
  
  <pre><code>import os
  
  def __init__():
      delete_stuff                # this runs but does nothing on its own
  </code></pre>
  
  <p>It's not a matter of life and death, obviously, I was just curious if there's a simple solution that I'm not aware of.</p>
  
  <p>Thanks.</p>
  
  <p>EDITED for clarification</p>