Python and hello.World class example
I am trying to run the hello.World class example in the tutorial and am running into problems. I can compile the dll fine, and then copy the dll (and the boost_python.dll) into my python directory, and then start my Python interpreter. The library will import, but when I call either the greet or set methods, I get the following errors from within the Python interpreter: [greet]: Traceback (most recent call last): File "<interactive input>", line 1, in ? TypeError: unbound method Boost.Python.function object must be called with World instance as first argument (got str instance instead) [set]: Traceback (most recent call last): File "<interactive input>", line 1, in ? TypeError: unbound method Boost.Python.function object must be called with World instance as first argument (got nothing instead) I am failrly new to Python and even newer to Boost.Python, so there may be something very basic that I am missing. I am using boost 1.30, bjam to compile, MSVC 7.1, Python 2.2, and Windows XP. Note that I can compile and successfully execute the inital Hello World example (hello.cpp in the tutorial subdir). Thanks in advance for your help! David Brownell
David Brownell wrote:
I am trying to run the hello.World class example in the tutorial and am running into problems. I can compile the dll fine, and then copy the dll (and the boost_python.dll) into my python directory, and then start my Python interpreter. The library will import, but when I call either the greet or set methods, I get the following errors from within the Python interpreter:
[greet]: Traceback (most recent call last): File "<interactive input>", line 1, in ? TypeError: unbound method Boost.Python.function object must be called with World instance as first argument (got str instance instead)
[set]: Traceback (most recent call last): File "<interactive input>", line 1, in ? TypeError: unbound method Boost.Python.function object must be called with World instance as first argument (got nothing instead)
I am failrly new to Python and even newer to Boost.Python, so there may be something very basic that I am missing. I am using boost 1.30, bjam to compile, MSVC 7.1, Python 2.2, and Windows XP. Note that I can compile and successfully execute the inital Hello World example (hello.cpp in the tutorial subdir).
Hi David, FYI, Boost.Python has its own mailing list. It would be nice to see you there ;-) http://mail.python.org/mailman/listinfo/c++-sig Anyway, I'm a bit lost. Could you please copy and paste the exact Python session? Have you tried the example session in the tutorial?: >>> import hello >>> planet = hello.World() >>> planet.set('howdy') >>> planet.greet() 'howdy' Regards, -- Joel de Guzman joel at boost-consulting.com http://www.boost-consulting.com http://spirit.sf.net
David Brownell wrote:
I am trying to run the hello.World class example in the tutorial and am running into problems. I can compile the dll fine, and then copy the dll (and the boost_python.dll) into my python directory, and then start my Python interpreter. The library will import, but when I call either the greet or set methods, I get the following errors from within the Python interpreter:
[greet]: Traceback (most recent call last): File "<interactive input>", line 1, in ? TypeError: unbound method Boost.Python.function object must be called with World instance as first argument (got str instance instead)
[set]: Traceback (most recent call last): File "<interactive input>", line 1, in ? TypeError: unbound method Boost.Python.function object must be called with World instance as first argument (got nothing instead)
I am failrly new to Python and even newer to Boost.Python, so there may be something very basic that I am missing. I am using boost 1.30, bjam to compile, MSVC 7.1, Python 2.2, and Windows XP. Note that I can compile and successfully execute the inital Hello World example (hello.cpp in the tutorial subdir).
Hi David,
FYI, Boost.Python has its own mailing list. It would be nice to see you
Joel, thank you for your reply - I am now a member of the Boost Python
mailing list as well. I am actually quite embarrassed as to what my problem
was, and it is painful to admit it here in public :) I wasn't creating a
new instance of the object before I tried to access the object's methods.
Sometimes python's syntax is so easy, I expect it to read my mind! Adding
that "fix" makes the quite logical errors go away.
"Joel de Guzman"
http://mail.python.org/mailman/listinfo/c++-sig
Anyway, I'm a bit lost. Could you please copy and paste the exact Python session? Have you tried the example session in the tutorial?:
>>> import hello >>> planet = hello.World() >>> planet.set('howdy') >>> planet.greet() 'howdy'
Regards, -- Joel de Guzman joel at boost-consulting.com http://www.boost-consulting.com http://spirit.sf.net
participants (2)
-
David Brownell
-
Joel de Guzman