title: How To Reduce Python Script Memory Usage
body: <p>I have a very large python script, 200K, that I would like to use as little memory as possible.  It looks something like:</p>
  
  <pre><code># a lot of data structures
  r = [34, 78, 43, 12, 99]
  
  # a lot of functions that I use all the time
  def func1(word):
      return len(word) + 2
  
  # a lot of functions that I rarely use
  def func1(word):
      return len(word) + 2
  
  
  # my main loop
  while 1:
     # lots of code
     # calls functions
  </code></pre>
  
  <p>If I put the functions that I rarely use in a module, and import them dynamically only if necessary, I can't access the data.  That's as far as I've gotten.</p>
  
  <p>I'm new at python.</p>
  
  <p>Can anyone put me on the right path?  How can I break this large script down so that it uses less memory?  Is it worth putting rarely used code in modules and only calling them when needed?</p>