f



Sending a python argument to a Boost.Python function

I have a python class that wraps a boost.python object. I am using a boost.python library function that requires the raw boost.python object. I want to be able to pass the python object to the boost api function.

Is there a hook available on the python side that instructs boost to perform a conversion?

Hypothetically, it would be something like this:

class EggWrapper(object):
    def __init__(self, egg):
        object.__setattr__(self, '_egg', egg)

    def __getattribute__(self, name):
        egg = object.__getattribute__(self, '_egg')

        if name=='_egg':
            return egg

        if name in EggWrapper.__dict__:
            return object.__getattribute__(self, name)

        return getattr(egg, name)

    def __setattr__(self, name, value):
        egg = object.__getattribute__(self, '_egg')
        setattr(egg, name, value)

    def magic_boost_conversion_unicorn_hook(self):
        'this is automatically called by boost to convert arguments'
        egg = object.__getattribute__(self, '_egg')
        return egg
        

import myboostlib

egg = EggWrapper(myboostlib.getEgg())

myboostlib.spam(egg)


Where the signature for spam is: spam(class boost::python::api::object)
And myboostlib.getEgg() returns a boost::python::api::object

- I do not have the ability to modify the library or any C/C++ code, the solution must be entirely on the python side.

- I can't change the calling convention. The wrapped object must be used (i.e. I can't just say myboostlib.spam(egg._egg), though that is the desired result). So the solution should be incorporated into the EggWrapper class.

- I'm only interested in solutions that reflect expert knowledge of Boost.Python, since I believe I have already considered all the trivial solutions.

So my question is, does magic_boost_conversion_unicorn_hook() exist, and if so, how is it spelled?


Thanks,
~ Ken





0
kenseehart
9/23/2015 7:02:07 PM
comp.lang.python 77058 articles. 6 followers. Post Follow

1 Replies
555 Views

Similar Articles

[PageSpeed] 59

Try that question here:
https://mail.python.org/mailman/listinfo/cplusplus-sig

Laura
0
Laura
9/24/2015 1:16:42 PM
Reply:

Similar Artilces:

python is a python
python is a python ...

Python to Python communication
Hello, I have a group of Python programms which I want to teach to "talk to each other". All run on Windows, on the same computer or in the same intranet. Security of communication is not an issue (encryption on lower level protocols / intra computer communication). Partially these programs are using wxPython. It is important that the communcation is "only an added feature", I am not willing to spend big memory / computing ressources on it. So I googled and came up with at least the following opportunities: XMLRPC - quite "simple" to implement within py...

Embedding Python in Python
Hi, I've been programming in Python for a couple of weeks now and am quite impressed with the language - it was very easy to learn (it actually reminds me a lot of programming in BASIC many many years ago - it's very fast to hack together a couple lines of code in interactive mode). I'm throwing together a simple little game (sort of a MUD-type thing) as my first 'big' project, and I thought it would be cool to be able to script the game in Python. Basically, I want to be able to type scripts in from within the game and attach them to objects, monsters, rooms, whatever. N...

Python mascot? How about a Pythoneer?
I've been thinking that a good Python mascot might help in raising public awareness of Python. The problem with a snake as a mascot is that it is not anthropomorphic enough. An effective mascot has to have something approximating two arms, two legs, and a head, so that he can be put into various interesting situations and adventures. (At the very least, he has to be able to work a keyboard and a mouse!) Good examples can be found in some of the imaginative things that have been done with Linux's Tux. So a snake is out. So are Terry Gilliam's wonderful cartoons for the Flyin...

Invoking Python from Python
Hi all, I have a need to create a Python script on the fly from another Python program and then execute the script so created. Do I need to invoke Python through os.spawnl or is there a better way? Thanks, -- John Am Tue, 08 Nov 2005 08:10:25 -0800 schrieb John Henry: > Hi all, > > I have a need to create a Python script on the fly from another Python > program and then execute the script so created. Do I need to invoke > Python through os.spawnl or is there a better way? Hi, creating source code with a script, is no good solution. Once I had to maintain lisp code w...

Sending cookies with python. When download with python
I need to download files off a password protected website. So if I try to download files off the site with python I will be blocked. Is there anyway to send cookies with python. So I will be authenticated. On Jun 5, 9:14 am, moishyyeh...@gmail.com wrote: > I need to download files off a password protected website. So if I try > to download files off the site with python I will be blocked. Is there > anyway to send cookies with python. So I will be authenticated. Yes. I haven't done it but I know you should be looking at urllib2 and cookielib. I'm sure you can find some exam...

Embedded Python
I embed multiple interpreters. I create the interpreter and modules in the primary thread of my application: PyEval_AcquireLock(); thread = Py_NewInterpreter(); PyThreadState_Swap(thread); ....initialize modules, etc.... PyThreadState_Swap(maininterpreter); PyEval_ReleaseLock(); Then I create a C thread called "main" which calls a function called "Main" in the Python interpreter: PyEval_AcquireLock(); PyThreadState_Swap(thread); moduledictionary = PyModule_GetDict(pmodule); PyObject_CallObject(PyDict_GetItemString(moduledictionary, "Main"), NULL); PyThreadSta...

Executing a python script with arguments from a python script
Hi, I need to call a python script, with command line arguments (it is an autonomous script with a __main__), from within another python script. Can I use exec() or execfile() for this? How to pass the arguments? Thanks, Olivier. olaufr@gmail.com wrote: > Hi, > > I need to call a python script, with command line arguments (it is an > autonomous script with a __main__), from within another python script. > Can I use exec() or execfile() for this? How to pass the arguments? > > Thanks, > > Olivier. > Obligatory "ugh." Are you sure you want to do...

Understanding python functions
Hi: I have begun learning Python by experimenting with the code snippets here: http://hetland.org/writing/instant-python.html In the section on functions, Magnus Lie Hetland writes: -------------------------------------------------------------------- For those of you who understand it: When you pass a parameter to a function, you bind the parameter to the value, thus creating a new reference. If you change the �contents� of this parameter name (i.e. rebind it) that won�t affect the original. This works just like in Java, for instance. Let�s take a look at an example: def change(some_l...

Injecting python function in an embedded python engine
Hi All in the list, I've embedded python v2.6.x engine into my application without any problem. Now I would like to inject some additional functions after importing a python module. So, basically I'm importing a python module via PyImport_ImportModule() function. The python module is a simple set of functions and I would check if some functions does exist or not, than if doesn't I would add it from my C application. Checking if a function does exist or not isn't an issue, it works without any problem, my problem is only how to inject a new function in an already imported modul...

Boost + Python C/API: Mixing python return types with boost return types
Hello, I'm new to Boost & Python and I'm diving straight in by trying to write an extension module to a third party library. Foolishness probably, but I don't have much choice! My question is how can I write a C++ method that will either return a boost wrapped C++ class or a Python object type depending on some internal value? So I want to do something like: PyObject* Variant::getValue() { switch (type) { case INT: return Py_BuildValue("i", union.int); break; case SOMECLASS: ?????? } } But I can...

injecting functions into a python sandbox within a python program
I have a large Python 2.5 program that I want my users to be able to "extend" using a Python script. However, I want their script to run in a sandbox within the overall program so that they only have access to the rest of the program via a single simple interface. Note that this is not meant to be a real anti-hacker type security sandbox - just "help them to avoid shooting themselves in the foot" type security. So I created a single object that has the interface that I want them to access. I call their script via "exec" passing the single interface object ...

Test a Python function within Python without importing
Hi I have a window that allows the user to write a python function (scite). Let's say the function always has 1 input param and 1 output value. eg.: <code> def modify_string(stuff_to_modify): modified_string = 'Modified: %s' % stuff_to_modify return modified_string <code> By compiling this code I can easily check whether the "string" is valid python code: try: com = compile(code, '<string>','exec') except Exception, msg: # Show msg to user if exeption occurred pass If compilation and other checks went fine, I would l...

Python in the enterprise: "Python Slithers into Systems" / Why Python? (eweek 2007)
Last summers box office hit "snakes on a plane" was the unlikely story of a batch of snakes getting loose in flight on a 747. In what some might view as just as unlikely, ITA Software is using the Python language to empower its airline reservation system. Many computer language purists say that languages such as Java, C++ or C should be used for enterprise applications. However, ITA, a Cambridge, Mass., provider of airline IT software and services, is proving that dynamic languages such as Python can be rock-solid for enterprise work. Indeed, ITA in September 2006 a...

Web resources about - Sending a python argument to a Boost.Python function - comp.lang.python

Argument (linguistics) - Wikipedia, the free encyclopedia
In linguistics , an argument is an expression that helps complete the meaning of a predicate . Most predicates take one, two, or three arguments. ...

Arguments in Officer William G. Porter's appeal will be heard in March - Baltimore Sun
An aggressive timetable initially set for the trials of the six Baltimore police officers charged in the arrest and death of Freddie Gray has ...

"And beyond the constitutional argument, adults younger than age 25 are just as entitled to the tools ...
"Indeed, 18-to-24-year-old women are especially likely to be targets for rape, but more broadly 18-to-24-year-olds are especially likely to be ...

The News Notices the News: Clinton's Electability Argument "Flies in the Face" of Polling Data
Bernie Sanders says he's the Democrats' most electable candidate. Watch more: http://on.msnbc.com/1RiaBmh Posted by Morning Joe on Monday, January ...

Police: Argument over turtle prompts SWAT standoff - CBS News 8 - San Diego, CA News Station - KFMB Channel ...
A SWAT standoff is underway in the 3500 block of Linda Vista Drive. A man wanted for making criminal threats is holed up inside a mobile home ...

Donald Trump makes the religious argument at Liberty University
CBS News Donald Trump makes the religious argument at Liberty University CBS News LYNCHBURG, Virginia Before GOP presidential candidate Donald ...

Liberal Senator Says She Wants To Avoid ‘Constitutional Arguments’ During Hearing On Obama’s Executive ...
Liberal Senator Says She Wants To Avoid ‘Constitutional Arguments’ During Hearing On Obama’s Executive Gun Action

Judd Apatow Shoots Down Too-Much-TV Argument During Netflix’ ‘Love’ Panel – TCA
While some TV network execs may be giving the too-much-TV talk, Judd Apatow thinks it’s the best of times, not the worst of times. “It’s an amazing ...

Tom Benson, estranged heirs make arguments in appeals hearing on Saints, Pelicans owner's competency
Lawyers for New Orleans Saints and Pelicans owner Tom Benson and his estranged heirs made arguments Thursday in the appeals hearing regarding ...

Bernie Sanders’ Nostalgic ‘Closing Argument’ Tugs At The Heart
... from what may have been one of the most unsettled times in the United States. Sanders’ new ad relies on nostalgia to make a powerful argument. ...

Resources last updated: 1/25/2016 5:10:46 AM