Can A Class Variable Be An Instance Of The Class?
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 I want a chosen generator (2) to be as
Solution 1:
You can do something like this:
classFiniteField11: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.
Post a Comment for "Can A Class Variable Be An Instance Of The Class?"