• <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>

            力為的技術博客

            聯系 聚合 管理
              154 Posts :: 1 Stories :: 561 Comments :: 0 Trackbacks

            最近看了下用Boost.Python封裝C++供Python調用。在搗鼓的過程中遇到一個費解的異常:
            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調用

            構造一個Vector3對象,測試其功能

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

            3. 輸出結果
            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的問題,實在找不出封裝的過程有什么問題。
            仔細分析下可以猜測2中的pt似乎并不是Vector3的一個實例。
            驗證一下:
            pt = AnyCAD.Vector3()
            pt.x 
            = 100
            pt.length()
            print pt

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

            輸出結果:

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

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

            評論

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

            岛国搬运www久久| 久久97久久97精品免视看| 久久国产精品成人免费| 久久伊人精品青青草原高清| 国产99久久久国产精品小说| 久久精品九九亚洲精品| 大美女久久久久久j久久| 国产成人久久精品一区二区三区| 国产一区二区精品久久| 久久精品国产久精国产果冻传媒 | 99久久婷婷国产综合精品草原| 伊人色综合久久天天人守人婷 | 久久伊人色| 精品国产一区二区三区久久| 亚洲国产另类久久久精品| 天堂无码久久综合东京热| 国产成人精品久久亚洲高清不卡 | 精品国产乱码久久久久软件| 久久强奷乱码老熟女网站| 国产精品99久久99久久久| 亚洲精品白浆高清久久久久久 | 精品免费久久久久久久| 久久久久人妻一区二区三区| 亚洲国产成人精品无码久久久久久综合 | 91精品国产9l久久久久| 久久精品国产亚洲AV电影| 久久这里只有精品首页| 久久精品这里只有精99品| 久久99精品久久久久久野外| 亚洲国产二区三区久久| 久久国产成人午夜AV影院| 97久久精品人人做人人爽| 国产精品成人99久久久久| 成人亚洲欧美久久久久| 日本欧美国产精品第一页久久| 老司机午夜网站国内精品久久久久久久久 | 一本久道久久综合狠狠躁AV| 亚洲精品国产综合久久一线| 久久精品国产亚洲精品| 久久精品亚洲乱码伦伦中文| 久久精品国产亚洲AV忘忧草18|