今天被坑的够惨,就这个模式的代码,传参进门前是str,进家再出来就成tuple了,为啥?在家发生了啥。

class Grobid_test(object):

    def __init__(self, a, b):
        self._a = a,
        self._b = b,
        print(type(self._a))
        print(type(self._b))

g = Grobid_test("A", "B")


# <class 'tuple'>
# <class 'str'>

 

一顿操作,最终发现,原来是每个self语句后边本应该什么都没有,只接受值,如果接收到值+逗号,就会把值和逗号组合当成元祖处理了。。

class Grobid_test(object):

    def __init__(self, a, b):
        self._a = a
        self._b = b
        print(type(self._a))
        print(type(self._b))

g = Grobid_test("A", "B")


# <class 'str'>
# <class 'str'>

 

posted on 2019-10-15 19:09  天马行宇  阅读(260)  评论(0编辑  收藏  举报