[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: embedding
From: "Michael P. Reilly" <arcege () shore ! net>
Date: 1999-08-06 21:32:47
[Download RAW message or body]
Rich Salz <salzr@certco.com> wrote:
: The following (excerpted, no error-checking)
: PyObject* mod = PyImport_AddModule("__main__");
: PyObject* mdict = PyModule_GetDict(mod);
: PyObject* obj = get_a_python_object();
: PyDict_SetItemString(mdict, "YOUR NAME HERE", pyd);
: This seems simpler than Reilly's method. So is my code wrong, or (gasp) is
: there More Than One Way To Do It?
: /r$
More than one way to do it in Python? "Ni!" to you. ;) Yes, there is
more than one way to do it. I don't think it's simplier myself, but
that's just me.
It is the (exact) difference between:
mod = __import__("__main__")
setattr(mod, "YOUR NAME HERE", obj)
and:
mod = __import__("__main__")
mdict = mod.__dict__
mdict['YOUR NAME HERE'] = obj
Using the attribute interface is preferable to digging into the
internals. (I won't get into spaces in namespace names.)
-Arcege
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic