Exemplo n.º 1
0
def test_constructor():
    p1 = Point(10, 20)  # __init__ 수행
    print("x={}, y={}, count_of_instance={}".format(p1.x, p1.y, Point.get_count_of_instance()))
    p2 = Point(100, 200)
    print("x={}, y={}, count_of_instance={}".format(p2.x, p2.y, Point.get_count_of_instance()))

    del p1 # __del__ 소멸자 수행
    print("count_of_instace = {}".format(Point.get_count_of_instance()))
Exemplo n.º 2
0
def test_operator():
    p = Point(10, 20)
    print("p + int: ", p + Point(5, 5))  # __add__ 호출

    print("Point - Point: ", p - Point(10, 10))  # __sub__ 호출

    print("Point == Point: ", p == Point(10, 20))  # __eq__ 호출

    print("int + Point: ", 10 + p)
Exemplo n.º 3
0
def test_constructor():
    p1 = Point(10, 20)  # __init__ 수행
    print(
        f"x = {p1.x}, y = {p1.y}, count_of_instance = {p1.count_of_instance}")
    p2 = Point(100, 200)
    print(
        f"x = {p2.x}, y = {p2.y}, count_of_instance = {p2.count_of_instance}")

    del p1  # __del__ 수행
    print(f"count_of_instance = {Point.get_count_of_instance()}")
Exemplo n.º 4
0
def test_construcotr():
    p1 = Point(10, 20)
    print("x={}, y= {}, count_ofinstance= {}".format(
        p1.x, p1.y, Point.get_count_of_instance()))
    p2 = Point(30, 40)
    print("x={}, y= {}, count_ofinstance= {}".format(
        p2.x, p2.y, Point.get_count_of_instance()))

    del p1  # __del__ 소멸자 수행

    print("count_ofinstance= {}".format(Point.get_count_of_instance()))
Exemplo n.º 5
0
def test_operator():
    p = Point(10, 20)

    print("p + int: ", p + 10)
    print("Point + Point: ", p + Point(10, 20))

    print("p - int: ", p - 5)
    print("Point - Point: ", p - Point(10, 10))

    print("Point == Point: ", p == Point(10, 20))

    print("int + Point: ", 10 + p)   #역이행 연산자
Exemplo n.º 6
0
def test_bound_instance_method():
    # 객체 인스턴스를 직접 호출하여 접근하는 방법
    # 인수로 self는 전달하지 않음
    p = Point()
    p.set_x(10)
    p.set_y(20)
    p.draw()
Exemplo n.º 7
0
def test_unbound_class_method():
    # 클래스 객체를 통해 우회 접근
    # self 인수에 객체의 참조 주소를 전달해야 함
    p = Point()
    Point.set_x(p, 10)
    Point.set_y(p, 20)
    Point.draw(p)
Exemplo n.º 8
0
def test_to_string():
    p = Point(10, 20)
    print("p = ", p)

    # repr 함수 -> __repr__ 메서드가 수행
    print("repr(p)", repr(p))

    p2 = eval(repr(p))  # repr을 이용한 객체의 복원
    print(p2, type(p2))
Exemplo n.º 9
0
def test_to_string():
    p = Point(10, 20)
    print("p =", p)

    # repr 한수 -> __repr__ 메서드가 수행
    print("repr(p) :", repr(p))

    p1 = eval(repr(p))  # repr을 이용한 객체의 복원
    print(p1, type(p1))
Exemplo n.º 10
0
def test_to_string():
    p = Point(10, 20)
    print("p = ", p)     #출력값: 주소  --> 문자열화 필요 (point.py에 __str__ 지정하기)

    #repr함수 -> __repr__메서드 수행
    print("repr(p): ", repr(p))

    #eval함수 -> 객체 복원
    p2 = eval(repr(p))
    print(p2, type(p2))
Exemplo n.º 11
0
def test_to_string():
    p = Point(10, 20)
    print("p = ",
          p)  #   원래 __str__은 주소를 출력한다. 그래서 point에 새로 만들고 return값을 수정했다.

    # repr 함수 -> __repr__ 메서드가 수행
    print("repr(p)", repr(p))

    p2 = eval(repr(p))  #   repr을 이용한 객체의 복원
    print(p2, type(p2))
Exemplo n.º 12
0
def test_other_methods():
    # static, class 멤버에 접근
    print("참조 카운트:", Point.get_count_of_instance())
    Point.static_method()
Exemplo n.º 13
0
def test_other_method():
    #static, class멤버에 접근하기
    print("참조 카운트: ", Point.get_count_of_instance())    #get_count_of_instance에는 cls인자가 있고, Point클래스를 받기 때문에 따로 적어주지 않아도 된다.
    Point.static_method()
Exemplo n.º 14
0
from oop.point import ColorPoint
from oop.point import Point

colorPoint = ColorPoint(2, 5, "green")
colorPoint.recolor("blue")

p = Point(1, 3)
print(p)