Q:

Basic confusion with classes & modules (Specially with "self")

I thought that this code would work 
class A:
    def __init__(self):
        self.x = 1
        B = self.create_b()
        print(B.y)

    def create_b(self):
        class B:
            def __init__(self):
                self.y = self.x
        return B
A = A()

but I receive the following error
AttributeError: type object 'B' has no attribute 'y'

What am I doing wrong?

A:

You're confusing classes with class instances (not Python modules). In Python class statements are executable and create a callable object that you must then be called to create instance objects of the class that was defined.
Regular methods of a class automatically receive a first argument that's the instance they belong to, and by convention, this argument is usually called self.
Here's what I mean:
class A:
    def __init__(self):
        self.x = 1
        B = self.create_b()  # Create B class.
        b = B(self)  # Create instance of B class passing this instance of A.
        print(b.y)

    def create_b(self):
        class B:
            def __init__(self, a_inst):
                self.y = a_inst.x
        return B

a = A()  # -> 1

