• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            力為的技術(shù)博客

            聯(lián)系 聚合 管理
              154 Posts :: 1 Stories :: 561 Comments :: 0 Trackbacks

            最近看了下用Boost.Python封裝C++供Python調(diào)用。在搗鼓的過程中遇到一個費解的異常:
            TypeError: unbound method Boost.Python.function object must be called with MyClass instance as first argument (got nothing instead)
            最終盡管可以正常使用了,但仍是一頭霧水。



            前期工作

            1. 用Python封裝C++類Vector3:

            1   class_<Vector3>("Vector3")
            2      .def_readwrite("x"&Vector3::x)
            3      .def_readwrite("y"&Vector3::y)
            4      .def_readwrite("z"&Vector3::z)
            5      .def("normalise",   &Vector3::normalise)
            6      .def("length",      &Vector3::length)
            7      .def("distance",    &Vector3::distance)
            8      .def(self += self)
            9      .def(self -= self)


            2. 用Python調(diào)用

            構(gòu)造一個Vector3對象,測試其功能

            pt = AnyCAD.Vector3
            pt.x 
            = 100
            pt.length()

            3. 輸出結(jié)果
            100.0
            Traceback (most recent call last):
              File 
            "D:\testx.py", line 17in <module>
                pt.length()
            TypeError: unbound method Boost.Python.function object must be called with Vecto
            r3 instance as first argument (got nothing instead)


            4. 修改測試腳本:
            pt = AnyCAD.Vector3()
            pt.x 
            = 100
            pt.length()

            運行正常。

            問題分析

            Python拋出的異常說是unbound method的問題,實在找不出封裝的過程有什么問題。
            仔細(xì)分析下可以猜測2中的pt似乎并不是Vector3的一個實例。
            驗證一下:
            pt = AnyCAD.Vector3()
            pt.x 
            = 100
            pt.length()
            print pt

            pt2 
            = AnyCAD.Vector3
            pt2.x 
            = 100
            pt2.length()
            print pt

            輸出結(jié)果:

            <AnyCADPlatformPython.Vector3 object at 0x04732FC0>
            <class 'AnyCADPlatformPython.Vector3'>

            至此真相大白。
            posted on 2010-03-16 20:17 力為 閱讀(7011) 評論(1)  編輯 收藏 引用

            評論

            # re: 【Boost.Python】unbound method 錯誤 2013-03-04 16:33 tb
            測試才行 呵呵  回復(fù)  更多評論
              


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            一本久久a久久精品综合夜夜 | 久久男人AV资源网站| 久久99国产一区二区三区| 伊人情人综合成人久久网小说| 久久精品国产男包| 亚洲国产精品一区二区久久| 久久久久久久综合日本亚洲 | 久久精品国产AV一区二区三区| 久久这里的只有是精品23| 少妇人妻88久久中文字幕| 国内精品久久久久久久亚洲 | 久久99国产精品久久久| 久久久久久久波多野结衣高潮 | 久久精品国产免费观看三人同眠| 久久夜色精品国产网站| 青青久久精品国产免费看| 久久久久久狠狠丁香| 午夜精品久久久久| 久久精品国产秦先生| 久久久午夜精品福利内容| MM131亚洲国产美女久久| 亚洲狠狠婷婷综合久久久久| 97精品国产97久久久久久免费| 久久无码专区国产精品发布| 国产精品中文久久久久久久| 大香网伊人久久综合网2020| 国产999精品久久久久久| 久久精品国产乱子伦| 青青热久久国产久精品| 99国产精品久久久久久久成人热| 国产91色综合久久免费| 久久久SS麻豆欧美国产日韩| 久久影视国产亚洲| 国产精品久久久久久久午夜片| 69国产成人综合久久精品| 一本色道久久88精品综合 | 国内精品久久久久久99蜜桃| 久久久精品久久久久影院| 久久99久久成人免费播放| 66精品综合久久久久久久| 国内精品久久人妻互换|