f



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 module.

Thanks in advance,
Roberto Fichera.
0
kernel1 (1)
4/6/2009 4:58:12 PM
comp.lang.python 77058 articles. 6 followers. Post Follow

0 Replies
893 Views

Similar Articles

[PageSpeed] 8

Reply:

Similar Artilces:

python is a python
python is a python ...

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...

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...

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 ...

embedding python in python #3
Hi, anyone had any experiences in embedding python in python? I've tried to do this but it doesn't work. eval("from Tkinter import *") Thanks maurice Use exec. On Wed, Sep 29, 2004 at 09:23:28AM +0000, Maurice LING wrote: > Hi, > > anyone had any experiences in embedding python in python? > > I've tried to do this but it doesn't work. > > eval("from Tkinter import *") Maurice LING <mauriceling@acm.org> wrote in message news:<415a7f0b$1@news.unimelb.edu.au>... > Hi, > > anyone had any experiences in embeddi...

Embedding Python in Python #2
Anyone know a good way to embed python within python? Now before you tell me that's silly, let me explain what I'd like to do. I'd like to allow user-defined scriptable objects. I'd like to give them access to modify pieces of my classes. I'd like to disallow access to pretty much the rest of the modules. Any ideas/examples? -Robey You probably want something like this: globalDict = {} exec(stringOfPythonCodeFromUser, globalDict) globalDict is now the global namespace of whatever was in stringOfPythonCodeFromUser, so you can grab values from that and selectivly im...

pass bool values to the Python function in embedded python 3.0
Guys, How do I transfer the parameters ? in python code: traceback.format_exception(exc_type, exc_val, exc_tb, 2, True) in C++ code: obFunc_format_exception = PyObject_GetAttrString(modTB, "format_exception"); tbArgs = Py_BuildValue("OOOii", exc_type, exc_value, exc_tb, 2, 1); tbResultList = PyObject_CallObject(obFunc_format_exception , tbArgs); how do I pass True to the Python function in the C++ code? On Mar 7, 5:38=A0pm, BigHand <hewei...@gmail.com> wrote: > Guys, How do I transfer the parameters ? > in python code: > traceback.format_exception(exc_type...

Embedded python 'scripting engine' inside Python app
I am writing a python app (using PyQt, but that=E2=80=99s not important = here), and want my users to be able to write their own scripts to = automate the app=E2=80=99s functioning using an engine API hat I expose. = I have extensive experience doing this in a C++ app with the CPython = api, but have no idea how to do this outside of calling exec() from with = in Python :) Ideally their script would compile when the source changes and retain = it=E2=80=99s state and respond to callbacks from the api object. It = appears this won=E2=80=99t work with exec() because the script=E2=80=99s...

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 python, contained in my favourite web framework Quixote / medusa SOAP - around the same amount of work as XMLRPC ----> these two are fully buzzword compatible to enterprise communication needs. But are they really lightwight and needed? Banana - within the twisted framework. Is described as high performance with very litte ressources. From my scanning of twisted it is meanwhile possible to integrate it within wxPython and you only need to sell the soul of your firstborn for it; but I got the impression twisted rather needs a total commitment than a "I just need some banana, man" pyro - Python Remote Objects. Irmen de Jong has a "get Firefox" icon on it's page and he plays with the name "pyro", which makes a good impression. It looks rather "ripe", but: he is talking about "pyro 4.0" which will be incompatible with pyro ...

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 which stored its data in lisp code, too (incl. conditions and loops). It was a nightmare. Please explain what you want to do, and we will find a better solution. HTH, Thomas -- Thomas G�ttler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de Spam Catcher: niemand.leermann@thomas-guettler.de In article <pan.2005.11.08.16.21.11.472836@thomas-guettler.de>, Thomas Guettler <niemand.leermann@thomas-guettler.de> wrote: . . . >creating source code with a script, is no good solution. > >Once I had to maintain lisp code which stored its data in lisp code, too >(incl. conditions and loops). It was a nightmare. > >Please explain what you want to do, and we will find a better solution. . . . Yes and no. There are times when it's justified. I ENTIRELY agree, though, that many people who *think* that's what they...

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...

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==...

Embedding a python console inside a python application
Hi, I am starting an application in which I would like to have some scripting functionality. It will obviously be done in Python. The thing is that I would like my scripts to have access to the rest of the application as an object it could manipulate. I made some research and I found the code module, which allows to have a Python interpreter inside an application, but I am not sure if I can access to the "parent" which created this interpreter. A solution could be to launch my application through an interpreter, but the problem there is how to integrate it back into the GUI, redirec...

Python loading library containing embedded python...
I have a dll/so which embeds python. I can verify it works by compiling it as an executable and adding an appropriate main. I tried to write unit tests for this library with ctypes and a simple python script. Access violations and other strange things result. I suspect this is because I am basically embedding python in python at this point. How can I make my dll/so with embedded python support use via ctypes? If Py_NewInterpreter is the answer, why does it hang indefinitely? The dll/so must support use in processes which might contain other instances of Python. I can not change that requi...

Embedded python on systems without python installed
I have python successfully embedded in a program I wrote. What files do I need and where do I need to put them so that it can run on systems that don't have python installed? KillSwitch wrote: > I have python successfully embedded in a program I wrote. > > What files do I need and where do I need to put them so that it can > run on systems that don't have python installed? > I embed python in Delphi apps, and the only thing I add is python24.dll, which I put in the same directory as the Delphi executable, (but i you want a less clean install, you can put the dll als...

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_list): some_list[1] = 4 x = [1,2,3] change(x) print x # Prints out [1,4,3] As you can see, it is the original list that is passed in, and if the function changes it, these changes carry over to the place where the function was called. Note, however the behaviour in the following example: def nochange(x): x = 0 y = 1 nochange(y) print y # Prints out 1 Why is there no change now? Because we don�t change the value! The value that is passed in is the number 1 � we can�t change a number in the same way that we change a list. The number 1 is (and will always be) the number 1. What we did do is change the contents of the local variable (parameter) x, and this does not carry over to the environment. -------------------------------------------------------------------- What this looks like to me is what would happen if in C I passed a pointer to the list x to the function ch...

Embedding Python: Creating Python Class from Application
Hello All, Let's say I have a following python code: class hw_class: def __init__(self): pass def hello_world(self): print 'Hello World!' create_instance('hw_class', 'hw') hw.hello_world() hw = None The 'create_instance' function should be implemented in the application (powered by Delphi - P4D) which is embedding the Python.dll. I am trying to do this for some time having no success. I am missing these informations: 1. How to register global python variable from application which is embedding python? 2. How to assign this variable wi...

Can I embedding a (python) console on python program?
HI All, Apologize for being a newbie to python area and sorry for my English.=20 Actually what I need is embedding a python interactive console(or other shell console alike module) on my python program for debugging and controlling purpose during the program runtime.=20 For example, print/set some important value, query some runtime status when I remote login to host via telnet/ssh when the program running on the host. One of the idea is I can write the program use the GUI tech, but that is not fit for someone use a text based session. In summary, in my scheme, it should something looks like the GEdit extension - python console and but may interactive with tty/vty lines. Can anyone give a brief to me?=20 Thanks in advance. =20 --=20 Kee K Y CHEN <keekychen@gmail.com> On 02/20/10 16:38, Kee K Y CHEN wrote: > HI All, > > Apologize for being a newbie to python area and sorry for my English. > > Actually what I need is embedding a python interactive console(or other > shell console alike module) on my python program for debugging and > controlling purpose during the program runtime. > > For example, print/set some important value, query some runtime status > when I remote login to host via telnet/ssh when the program running on > the host. One of the idea is I can write the program use the GUI tech, > but that is not fit for someone use a text based session. > > In summary, in my scheme, it should something looks like...

real-time monitoring of propriety system: embedding python in C or embedding C in python?
Hi Group, at work, we are thinking to replace some legacy application, which is a hom= e-grown scripting language for monitoring and controlling a large experimen= t. It is able to read live data from sensors, do some simple logic and calc= ulations, send commands to other subsystems and finally generate some new s= ignals. The way it is implemented is that it gets a chunk of 1 second of da= ta (thousands of signals at sample rates from 1Hz to several kHz), does som= e simple calculations on selected signals, does some simple logic, sends so= me commands and finally computes some 1Hz...

Embedding Python
Hello, I'm embedding Python interpreter in a Win32 console application. I use C++. I would like to use the WinAPI LoadLibrary function to load the python dll at runtime (followed by GetProcAddress calls), so that I have to make no assumptions about the location of the dll. However I can't use the macro Py_DECREF if I load the dll this way. Is there a way to properly free python objects (specifically - dictionaries created by PyDict_New() and the object returned by PyRun_String()) not using Py_DECREF? Alternatively, is there a way to include the python header - to make the macro Py_DECREF available, but to be able to locate the python dll whenever python is installed? (The problem is that python may be installed anywhere, and the python dll does not always appear in system folders - sometimes it is in the python installation directory, thus it is unclear which targets to specify to the linker to search for the dll). I'd appreciate any help. Thanks in advance, yuri.feldman@gmail.com schrieb: > Hello, > > I'm embedding Python interpreter in a Win32 console application. I use > C++. > > I would like to use the WinAPI LoadLibrary function to load the python > dll at runtime (followed by GetProcAddress calls), so that I have to > make no assumptions about the location of the dll. > > However I can't use the macro Py_DECREF if I load the dll this way. > > Is there a way to properly free python objects (specifically ...

Python multithreading on cluster system? Embedding python in PVM?
Hi guys.I have read that one cannot perform true multithreading in python due to global interpreter lock mechanism.Suppose i have to implement a crawler on a say cluster system like clusterknoppix so that i can use parallel virtual machine (PVM)for programming in multiprocessor environment or say open MPI.Can i integrate python with PVM or MPI.Can i embed python into C for programming in multiprocessor environment.Is there any way of embedding python in PVM or MPI so that i can implement a true cluster based search engine? Any help would be very kind.Thanks. abhinav wrote: > Hi guys.I hav...

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...

Accessing members of Python class from C++ (Embedded Python)????
Hello everyone, Does anybody know about, have documentation on, or have any code samples on how to access class members from a python class in C++. Say I have a simple python script: --------------------------- class Animal: NumLegs = 5 Size = 4.5 --------------------------- How exactly do you access these members from C++. I know how to get the member if I know its name, ie. pkObject = PyDict_GetItemString(pkDict, "Animal"); int uiNumLegs = PyInt_AsLong(PyObject_GetAttrString(pkObject,"NumLegs")); But how do you iterate through all the class members and pri...

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 announced an agreement with Montreal-based Air Canada, a subsidiary of ACE Aviation Holdings, to develop a new reservation management system for the airline. Air Canadas next- generation reservation system will include reservations, inventory control and seat availability, along with airport check-in and airport operations modules. Sean Menke, Air Canadas executive vice president and chief commercial officer, said the new system "will be a key instrument in Air Canadas strategy to maintain market leadership through product and customer differentiation. Moreover, it will provide unprecedented flexibility and significant cost savings." Leaving Legacy Behind Dan Kelley, director of application integration at ITA, said ITA will deliver the system to Air Canada next year, and it will be deployed across the entire Air Canada network, including reservation...

Web resources about - Injecting python function in an embedded python engine - comp.lang.python

Getting High Injecting Snake Venom - YouTube
We met with a guy who's been injecting himself with snake venom for 20 years and he looks better than ever. Have a question? Steve is doing a ...

'Impostor' gynaecologist could have been injecting patients with unknown animal blood products
A Melbourne man accused of posing as a gynaecologist and IVF expert may have been giving his patients animal products as an alternative treatment ...

Sydney nurse Mavis Lopez on trial for manslaughter after injecting patient Nymphea Anderson with oral ...
A Sydney nurse has been accused of significantly contributing to the death of an elderly female patient by administering a mix of oral medication ...

East Orange: Kasia Rivera jailed for injecting a man’s penis with silicon - DailyTelegraph Search Search ...
A WOMAN who injected silicone into a man’s penis because he wanted her to make it bigger has been jailed after the dose killed him.

East Orange: Kasia Rivera jailed for injecting a man’s penis with silicon
A WOMAN who injected silicone into a man’s penis because he wanted her to make it bigger has been jailed after the dose killed him.

Sydney nurse Mavis Lopez on trial for manslaughter after injecting patient Nymphea Anderson with oral ...
A Sydney nurse has been accused of significantly contributing to the death of an elderly female patient by administering a mix of oral medication ...

'Imposter' gynaecologist could have been injecting patients with unknown animal blood products
A Melbourne man accused of posing as a gynaecologist and IVF expert may have been giving his patients animal products as an alternative treatment ...

Injecting centre approval fails to quell controversy
After a nine-year trial, an injecting centre in Kings Cross will be made permanent, but it remains clouded in controversy.

Injecting Poison Into Rhinos’ Horns To Fight Poaching
A South African game reserve called Sabi Sand is taking extreme steps to combat rhino poaching: they're injecting a mixture of poison and indelible ...

Contaminated water in Alberta renews questions about steam-injecting technology
A Canadian Natural Resources Ltd. oilsands operation that has contaminated a groundwater aquifer is renewing questions about a technology that ...

Resources last updated: 3/4/2016 12:21:03 PM