打印出现的问题

# -*- coding:utf-8 -*-
from decimal import *

getcontext().prec = 3


class Two_Lines(object):

    def __init__(self, v, w):
        self.v_vector = list(v)
        self.w_vector = list(w)

    def intersection_point(self):
        answer = []
        if self.v_vector[1] * self.w_vector[0] - self.v_vector[0] * self.w_vector[1] == 0:
            return 'BC-AD不能为零'
        elif (len(self.v_vector) or len(self.w_vector)) != 3:
            return '线段的参数个数发生错误!请重新输入!'
        else:
            answer.append((self.v_vector[1] * self.w_vector[2] - self.v_vector[2] * self.w_vector[1])/(self.v_vector[1] * self.w_vector[0] - self.v_vector[0] * self.w_vector[1]))
            answer.append((self.v_vector[2] * self.w_vector[0] - self.v_vector[0] * self.w_vector[2])/(self.v_vector[1] * self.w_vector[0] - self.v_vector[0] * self.w_vector[1]))
            return answer

    # def __str__(self):
    #     return 'x={} , y={}'.format(answer[0],a

c = (1, 66)
m = (3, 7, 16)
t = Two_Lines(c, m)
print t


最近在做一个练习的时候,我想打印一个东西,出现了一个错误:

<__main__.Two_Lines object at 0x0000000003475F28>


代码如上:

如图中的代码所示,在我想要打印出对象的解锁的时候,出现了一个__main__开头的错误

这个打印的其实 t 这个实例的存储地址,

这是没有定义 __repr__  或者 __str__ 方法,因此print时会使用系统的默认表格格式输出


你可能感兴趣的:(python,学习)