Delete objects, remove from dict
Hey, I have a dict of the main namespace in boost::python. Now I want to delete an object from the dict to unload/delete that object dict namespace = .. extract dict from __main__ module ...; namespace["test"] = object(555); namespace.remove("test"); // <- how can I do something like this with boost python? // Simon
namespace.remove("test"); // <- how can I do something like this with boost python?
namespace["test"].del(); See also: http://www.boost.org/doc/libs/1_44_0/libs/python/doc/v2/object.html Ralf
Hey and thanks for the answer! Unfortunately that doesn't seem to work. I'm using boost.python for Python 3 ( boost python 1.44? ) error C2039: 'del' : is not a member of 'boost::python::api::object' I've had a look on the reference manual but I don't understand if it's a free function or an method of object() ? Neither work .. The code i'm using: * object obj = mMainNamespace[ name.c_str() ]; obj.del();* // Simon On Mon, Oct 25, 2010 at 1:26 AM, Ralf W. Grosse-Kunstleve <rwgk@yahoo.com>wrote:
namespace.remove("test"); // <- how can I do something like this with boost python?
namespace["test"].del();
See also:
http://www.boost.org/doc/libs/1_44_0/libs/python/doc/v2/object.html
Ralf _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
I've only tried it with Python 2; I'm not setup for working with Python 3. Try boost::python::api::delitem(target, key); and if that fails too PyObject_DelItem(target.ptr(), key.ptr()); Ralf
From: Simon W <simwarg@gmail.com> To: Development of Python/C++ integration <cplusplus-sig@python.org> Sent: Mon, October 25, 2010 8:48:27 AM Subject: Re: [C++-sig] Delete objects, remove from dict
Hey and thanks for the answer! Unfortunately that doesn't seem to work. I'm using boost.python for Python 3 ( boost python 1.44? )
error C2039: 'del' : is not a member of 'boost::python::api::object'
I've had a look on the reference manual but I don't understand if it's a free function or an method of object() ? Neither work ..
The code i'm using: object obj = mMainNamespace[ name.c_str() ]; obj.del();
// Simon
On Mon, Oct 25, 2010 at 1:26 AM, Ralf W. Grosse-Kunstleve <rwgk@yahoo.com> wrote:
namespace.remove("test"); // <- how can I do something like this with boost
python?
namespace["test"].del();
See also:
http://www.boost.org/doc/libs/1_44_0/libs/python/doc/v2/object.html
Ralf
Oh, at second glance...
object obj = mMainNamespace[ name.c_str() ]; obj.del();
This cannot work! You need to do it the way I showed before. mMainNamespace[ name.c_str() ].del(); The [] operator returns a proxy object which supports the del since it still knows what the target object is. Once you've assigned the proxy object to boost::python::object the target information is lost. Ralf
Thanks that did the trick! On Mon, Oct 25, 2010 at 7:07 PM, Ralf W. Grosse-Kunstleve <rwgk@yahoo.com>wrote:
Oh, at second glance...
object obj = mMainNamespace[ name.c_str() ]; obj.del();
This cannot work! You need to do it the way I showed before.
mMainNamespace[ name.c_str() ].del();
The [] operator returns a proxy object which supports the del since it still knows what the target object is. Once you've assigned the proxy object to boost::python::object the target information is lost.
Ralf _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
participants (2)
-
Ralf W. Grosse-Kunstleve -
Simon W