티스토리 뷰

클래스를 따로 호출해도 변경된 클래스 변수를 적용 받는다.



def Test13_1():
    import ClassB
    from ClassB import cClassB

    obj1 = cClassB()
    obj1.AddValues(3)
    print(obj1.Value1)
    cClassB.Value1=40

def Test13_2():
    import ClassB
    from ClassB import cClassB

    obj1 = cClassB()
    obj1.AddValues(4)
    print(obj1.Value1)

if __name__=="__main__":

    from ClassB import cClassB
    Test13_1() # ==> 13
    Test13_2() # ==> 44
Value10 = 100

class cClassB:
    Value1 = 10

    def __init__(self):
        self.Value2 = 20

    def AddValues(self, valueIn):
        self.Value1 += valueIn
        self.Value2 += valueIn

    def AddValue2(self, valueIn):
        self.Value2 += valueIn

def AddValue10(valueIn):
    Value10 += 100

def SetClassValue(valueIn):
    cClassB.Value1 = valueIn

 

반응형