f



Embedding Python - Freeing Python Objects Not Using Py_DECREF

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,
0
1/17/2008 12:14:38 PM
comp.lang.python 77058 articles. 6 followers. Post Follow

1 Replies
868 Views

Similar Articles

[PageSpeed] 27

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

Use the Py_DecRef function, which was added for exactly this purpose.

Thomas

0
theller1 (133)
1/17/2008 2:17:19 PM
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...

Using Python To Launch Python
Hello All, I have a situation where I can count on a Python installation being available on a system, but I can't count on it being a version of Python needed by my application. Since my application has it's own version of Python installed with it how should I use the system Python to launch the version of Python that launches my Application. Yes, this is a convoluted process, but not all Pythons are built the same :) Right now I am leaning towards using exec to start a new process, but I thought I would check to see if anyone else has had the need to perform a task similar to thi...

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

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

Embedded python (use of modules) on system w/o Python installed
Hi there, I try to run a python script from a C program. The script uses the re (regex) module. The resulting executable must run on a system that has no lib and python script module, i.e no re.py How should I write my C program (I'd like to avoid any python file installation on target system) ? Now it is: --------- C prg ---------- #include <python2.2/Python.h> #define PYTHON_SCRIPT "test.py" int main(int argc, char * argv[]) { FILE *fd = fopen(PYTHON_SCRIPT, "r"); Py_Initialize(); PyRun_SimpleFile(fd, PYTHON_SCRIPT); Py_Finalize(); return 0; } -----...

Survey: Does your company use Python? Do you know a company that uses Python?
This is a survey to find as many companies using Python as we can. You can see the survey below: <http://spreadsheets.google.com/viewform?formkey=dHlwaUxIY2g0ZXpUMk4tREZDSTY3bkE6MA..> You don't need to work at the company to add it to this list! We will filter for duplicates. The answers to this survey will be kept private. If you still don't want to identify yourself, no problem! We just want to know where Python is being used. ...

Survey: Does your company use Python? Do you know a company that uses Python?
This is a survey to find as many companies using Python as we can. You can see the survey below: <http://spreadsheets.google.com/viewform?formkey=dHlwaUxIY2g0ZXpUMk4tREZDSTY3bkE6MA..> You don't need to work at the company to add it to this list! We will filter for duplicates. The answers to this survey will be kept private. If you still don't want to identify yourself, no problem! We just want to know where Python is being used. On 7 Ago, 21:15, VanL <van.lindb...@gmail.com> wrote: > This is a survey to find as many companies using Python as we can. You > ca...

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

Embedding Python: How to run compiled(*.pyc/*.pyo) files using Python C API?
Hello, I am trying to run compiled Python files (*.pyc and *.pyo) using Python C API. I am using the method PyRun_FileFlags() for this purpose. The code snippet is as follows:- PyCompilerFlags myFlags; myFlags.cf_flags=1; // I tried all values 0, 1 and 2 PyRun_FileFlags(script, file, Py_file_input, globals, locals, &myFlags); But unfortunately I get the following exception:- "DeprecationWarning: Non-ASCII character '\xf2' in file E:\test.pyc on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details" When I run the .py file, then t...

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

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

Using Python within a Python application.
Hello, everyone. I am doing some searching and winding up a little bit confused. I have a MUD client that I am writing using Python and wxWidgets, as some of you may remember. What I am looking to do now, is add "trigger" functionality to it. In essence, the application receives text from the game, and if it is in any of the trigger definitions, it acts on it by executing Python code that the user has associated with the action. So, the question is, what is the safe way to do this? I have found the 'compile' function, which returns a code object(?) which I would want to...

Using python to extend a python app
I'm writing a python app that works as a replacement for the menu that comes with most minimalist wms when you right click the root window. It's prettier and written completely in python. I'd like to provide hooks or some system so that people can write their own extensions to the app, for example adding fluxbox options, and then fluxbox users can choose to use that extension. But I'm not sure how to implement it. Right now the best idea I have is to have all desired extensions in a folder, import each .py file in that folder as a module using __import__, and then call...

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

Google Maps and Python: creating a map, embedding it, adding images, videos, markers, using python
I'm messing with Google-Maps. Is there a way I can create a map, embed it on a page (CSS/HTML/Javascript for this bit), and add images, videos, markers - using python? Any libraries available? Veek M wrote: > I'm messing with Google-Maps. Is there a way I can create a map, embed it > on a page (CSS/HTML/Javascript for this bit), and add images, videos, > markers - using python? Any libraries available? Hello, Googling for "google maps python client" returns https://developers.google.com/api-client-library/python/apis/mapsengine/v1 as the first...

I could use some help making this Python code run faster using only Python code.
I am new to Python however I would like some feedback from those who know more about Python than I do at this time. def scrambleLine(line): s = '' for c in line: s += chr(ord(c) | 0x80) return s def descrambleLine(line): s = '' for c in line: s += chr(ord(c) & 0x7f) return s def scrambleFile(fname,action=1): if (path.exists(fname)): try: f = open(fname, "r") toks = fname.split('.') while (len(toks) > 2): toks.pop() fname = '.'.j...

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

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

Ruby-Python; using python from within ruby
At the moment I'm looking at rails, it seems like a great framework. The only downside it has is its rather limited availability of 3rd party libraries. At the moment there are at least two libraries I need that are available to python but not to ruby (search engine, either xapian or lucene( python has bindings to both, ruby has neither), pydns and another custom python script) After looking for a solution I came across ruby-python (http://raa.ruby-lang.org/project/ruby-python/). Sadly enough it is a little bit outdated. It seems to need ruby 2.6 and python 1.5 while I'm using ruby 1....

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

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

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

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

Web resources about - Embedding Python - Freeing Python Objects Not Using Py_DECREF - comp.lang.python

Whitney embedding theorem - Wikipedia, the free encyclopedia
), if m > 0 . This is the best linear bound on the smallest-dimensional Euclidean space that all m -dimensional manifolds embed in, as the real ...

Improved Embedding Tools: Embedded Video Player API and oEmbed support
Launch of embedded video API and oEmbed support for facebook videos and posts

Instagram adds web embedding, makes sharing content on the web easier
... its platform beyond its mobile applications. Today, the photo sharing application has made it easier to share photos and videos with web embedding. ...

School transforms a generation by embedding Indigenous culture into its curriculum
From Indigenous dolls in the childcare centre to a discussion of the treatment of Adam Goodes, embedding Indigenous culture into the curriculum ...


Apple uploads individual iPhone 6 and Apple Watch promo videos to YouTube for your embedding pleasure ...
... iPhone 6 , and YouTube . What do you think? Discuss "Apple uploads individual iPhone 6 and Apple Watch promo videos to YouTube for your embedding ...

Instagram Adds Web Embedding in Bid for Real-Time Relevance
The real-time battle rages on. Instagram on Wednesday announced the latest in a string of recent updates, now allowing users to embed videos ...

The new Android Central Photography forums are open and feature Photosphere embedding
A great place to talk about the camera on your Android phone, and share the great pictures you take with it

Apple granted patent for embedding sapphire displays in LiquidMetal iPhone chassis
The U.S. Patent and Trademark Office on Tuesday issued Apple a patent describing a process in which an iPhone's display glass including sapphire ...

MPAA "embedding is infringement" theory rejected by court
Judge Posner A federal appeals court has decisively rejected a legal theory that would have placed anyone who embeds a third-party video on ...

Resources last updated: 2/28/2016 3:47:52 PM