Python - using a dictionary item as a object
<p>I am trying to make arguments easier to manage in a script I am putting together, I figured I'd wrap a bunch of related items into a dictionary, and pass the dictionary out of the func. pulling out the objects as I need them. </p>

<p>One of these items is a regEx, and I'm struggling to figure out how to structure things properly so I can make it work. </p>

<p>In my initial code (no dictionary). I am 'hard' coding the regex into the parser:</p>

<pre><code>def TopnTail(self,line):
    topRegEx = re.compile(r'(&lt;!--make_database header end--&gt;)') 
    tailRegEx = re.compile(r'(&lt;!--make_database footer start--&gt;)') 
    searchdumpTopOfPage = topRegEx.search(line)
    searchdumpBottomOfPage = tailRegEx.search(line)
    if searchdumpTopOfPage:
        self.__useLine=1
    if searchdumpBottomOfPage:
        self.__useLine=0  
    if self.__useLine == 1:
        self.trimmedLines = self.trimmedLines + line + "\n"
    return (self.trimmedLines)
</code></pre>

<p>in the 'dictionaried' version I want to set the variables in a setter:</p>

<pre><code>def siteDetails():
    baseDict = {'topRegex':'''re.compile(r'(&lt;!--make_database header end--&gt;)')''', 'tailRegex':'''re.compile(r'(&lt;!--make_database footer start--&gt;)')'''}
    return baseDict
</code></pre>

<p>and get to the compiled regex:</p>

<pre><code>def TopnTail(self,line):
    topRegEx = baseDict['topRegex'] 
    tailRegEx = baseDict['tailRegex'] 
    searchdumpTopOfPage = topRegEx.search(line)
    searchdumpBottomOfPage = tailRegEx.search(line)
    if searchdumpTopOfPage:
        self.__useLine=1
    if searchdumpBottomOfPage:
        self.__useLine=0  
    if self.__useLine == 1:
        self.trimmedLines = self.trimmedLines + line + "\n"
    return (self.trimmedLines) 
</code></pre>

<p>but this throws an error: </p>

<pre><code>line 35, in TopnTail
searchdumpTopOfPage = topRegEx.search(line)
AttributeError: 'str' object has no attribute 'search'
</code></pre>

<p>Which I am guessing means that its not actually made the regex object, but is still passing the string. </p>

<p>I appreciate that I am probably breaking about 3 cardinal rules here... but any suggestions about how to make it work would be fantastic... (also, first time playing with both classes and dictionaries... so please go easy if I've really messed up!)</p>
