How do I raise a custom exception from a package __init__?
<p>I have a package <code>__init__.py</code> that looks something like this:</p>

<pre><code>import sys

__required_python_version = (2,6, 0)

if sys.version_info &lt; __required_python_version:
    this_version = '.'.join([str(x) for x in sys.version_info[0:3]])
    required_version = '.'.join([str(x) for x in __required_python_version])
    raise PythonVersionError(this_version, required_version)

class PythonVersionError(Exception):
    def __init__(self, this_version, required_version):
        self.this_version = this_version
        self.required_version = required_version

    def __str__(self):
        return 'Python version %s is invalid.  Must be at least %s' % (self.this_ver, self.required_ver)
</code></pre>

<p>While I'm certain there is a more elegant way to format those version strings and I could probably get by using a standard exception, my real question is how would I do something like this?  Would the best approach be to move my custom exception into a separate file and import it?  Or should I wrap the version check in a function that executes when the <code>__init__</code> is run?  I'm just looking for recommendations on the preferred approach.</p>

<p>Thanks</p>
