title: Pylons: free module-level variables?
body: <p>Not even sure if module-level is correct here, but...</p>
  
  <p>I have a Pylons project and within the model component I have a global variable, doc, in <code>__init__.py</code> that I want to use from different Query objects. (doc is a Document handle on an XML file that I am using as a fake DB.) My question is, when does <code>__init__.py</code>'s scope end? Currently I am not freeing the Document with doc.unlink() and I am not sure where to put that.</p>
  
  <p>The alternative design I was thinking about deals with making the consuming object (Query) have a class-level variable of this doc (i.e. make it a singleton). But it appears that the life of my Query object is such that doc always gets reallocated a new Document handle.</p>
  
  <pre><code>class Query(object):
      doc = None 
  
      def __init__(self, content=None):
          self.content = content
          if self.doc == None:                        
              self.doc = parse(os.path.join(config['app_conf']['xmldb'], "sample_search_result.xml"))
  </code></pre>
  
  <p>I can tell because the address of the elements within the Document keep changing.</p>
  
  <p>Anyone want to help a noobie out?</p>