Can I add methods into def __init__?
<p>Using python 2.7.6, I have been trying to write a class that can extract pieces of xml data from a couple of xml files within a given zip file.  I want to be able to use any of the methods in any order once I am working with the class, so wanted the unzip stage to be behind the scenes, in the class.  </p>

<p>It is the first time I have really tried to make real use of a class as I am quite new to python, so I am learning as I go.</p>

<p>I defined methods to unzip the data to memory and was using those methods in other methods - then realised it would be horribly inefficient when using multiple methods.  Since the unzipping step is necessary for any method in the class, is there a way to build it into the init definition so it is only done once when the class is first created?</p>

<p>Example of what I currently have:</p>

<pre><code>class XMLzip(object):
    def __init__(self, xzipfile):
        self.xzipfile = xzipfile

    def extract_xml1(self):
        #extract the xmlfile to a variable

    def extract_xml2(self):
        #extract xmlfile2 to a variable

    def do_stuff(self):
        self.extract_xml1()
        ....

    def do_domethingelse(self):
        self.extract_xml1()
</code></pre>

<p>Is there a way to do something like I have shown below?  And if so, what is it called - my searches haven't been very effective.</p>

<pre><code>class XMLzip(object):
    def __init__(self, xzipfile):
        self.xzipfile = xzipfile

        def extract_xml1()
            # extract it here

        def extract_xml2()
            # extract it here

    # Now carry on with normal methods
    def do_stuff(self):
        ...
</code></pre>