Why does "self" outside a function's parameters give a "not defined" error?
<p>Look at this code:</p>

<pre><code>class MyClass():

    # Why does this give me "NameError: name 'self' is not defined":
    mySelf = self

    # But this does not?
    def myFunction(self):
        mySelf2 = self
</code></pre>

<p>Basically I want a way for a class to refer to itself without needing to name itself specifically, hence I want self to work for the class, not just methods/functions. How can I achieve this?</p>

<p><strong>EDIT:</strong> The point of this is that I'm trying to refer to the class name from inside the class itself with something like self.<strong>class</strong>._<em>name</em>_ so that the class name isn't hardcoded anywhere in the class's code, and thus it's easier to re-use the code.</p>

<p><strong>EDIT 2:</strong> From what I've learned from the answers below, what I'm trying to do is impossible. I'll have to find a different way. Mission abandoned.</p>

<p><strong>EDIT 3:</strong> Here is specifically what I'm trying to do:</p>

<pre><code>class simpleObject(object):
    def __init__(self, request):
        self.request = request

@view_defaults(renderer='string')
class Test(simpleObject):

    # this line throws an error because of self
    myClassName = self.__class__.__name__

    @view_config(route_name=myClassName)
    def activateTheView(self):
        db = self.request.db
        foo = 'bar'

        return foo
</code></pre>
