title: Turn python script into a function
body: <p>Assume I wrote a script <code>morning.py</code> which does a simple print statement</p>
  
  <pre><code># morning.py
  print 'Good morning'
  </code></pre>
  
  <p>Some hours later I've realized that I have to use this script in another script named <code>evening.py</code>. I am aware of two options. First, to invoke <code>morning.py</code> as a subprocess</p>
  
  <pre><code># evening.py
  import subprocess
  import shlex
  process = subprocess.Popen(shlex.split('python morning.py'))
  process.communicate()
  </code></pre>
  
  <p>This is the way I've initially chosen. The problem is that I want to pack my program (<code>morning</code> + <code>evening</code>) into a single executable. And to my understanding, from the exe file such call just won't work.</p>
  
  <p>Another option is to turn module <code>morning</code> into a function. For instance, like that</p>
  
  <pre><code># morning.py
  def morning_func():
     print 'Good morning'
  </code></pre>
  
  <p>Then I can simply call this function from the <code>evening</code> module</p>
  
  <pre><code># evening
  import morning
  morning.morning_func()
  </code></pre>
  
  <p>Here the problem is that unlike <code>morning</code> my actual initial script is quite extended and messy. There is no single function that I can execute to simulate script running flow. Wrapping the whole script in a function just does not feel right.</p>
  
  <p>What are possible solutions?</p>