Hi,<div><br></div><div>we embedded python into our application via Swig. Now we like to wrap the raw API functionality into a nicer more handleable module, but instead of repeating every function in this wrapper i thought about importing them into the namespace of the wrapper module. I like to give you an example of what we like to achive.</div>


<div><br></div><div>Swig generates a file called "ppms.py" which contains the API classes and functions.</div><div>Lets say the ppms.py contains a function called foo(). The wrapper.py should now import the function foo() of the module ppms into the local namespace.</div>


<div><br></div><div>the swig module:</div><div><br></div><div>def foo():</div><div>    pass</div><div><br></div><div>def foo0():</div><div>    pass</div><div><br></div><div>One possibility would be to repeat the function in the wrapper.py like:</div>


<div><br></div>import ppms.py<br>def foo():<br>    return ppms.foo()<div><br></div><div>def foo0():</div><div>    return ppms.foo0()+1</div><div><div><br></div><div>Imho this is a little ugly. So I thought about importing the content of ppms.py (the autgenerated one) into the namespace of the wrapper. Every definition of a fuction in the wrapper should overwrite the function in the imported module but a call to a function which is not defined in the wrapper goes right through. </div>


<div><br></div><div># wrapper.py - magic version</div><div>"magic_import" ppms.py</div><div><br></div><div>def foobar():</div><div>    return foo()  #calls foo of ppms.py</div><div><br></div><div><div>def foo0():</div>


<div>    return foo0()+1 #calls foo0 of ppms.py</div><div><br></div><div><br></div><div>Now using the magic version:</div><div><br></div><div>import wrapper</div><div><br></div><div>wrapper.foo() # looks in wrapper for foo() since it's not defined it falls back to ppms.foo()</div>


<div>wrapper.foobar() # calls wrapper.foobar() calls ppms.foo()</div><div>wrapper.foo0() # calls wrapper.foo0() calls ppms.foo0()</div><div><br></div><div>Hopefully the idea is not to stupid.. ;)</div><div>Tnx for your help.</div>


<div><br></div><div>Markus</div></div></div>