I would say that the proper way to get access to the variable is simply:
a_instance.z #instance variable 'z'
A.z #class variable 'z'
No need for Func1
and Func2
here.
As a side note, if you must write Func2
, it seems like a classmethod
might be appropriate:
@classmethod
def Func2(cls):
return cls.z
As a final note, which version you use within methods (self.z
vs. A.z
vs. cls.z
with classmethod
) really depends on how you want your API to behave. Do you want the user to be able to shadow A.z
by setting an instance attribute z
? If so, then use self.z
. If you don't want that shadowing, you can use A.z
. Does the method need self
? If not, then it's probably a classmethod, etc.