Can a class variable of say, class Foo
be a Foo
object itself?
For example, I\'m trying to build a class for the finite field of order 11, and
You can do something like this:
class FiniteField11:
def __init__(self, element):
self.elt = element
FiniteField11.generator = FiniteField11(2)
Your code fails because FiniteField11
was not defined when the class defintion was parsed.
Yes it can, but the name doesn't exist until the class statement finishes. Therefore, you have to set this class variable after creating the class, perhaps just below the class block or in the instance initializer.