473,699 Members | 2,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extending Embedded Python and execute external script

What i need from my C application to do ?
1) To execute a python script from file.
2) The python script will call functions in my C application.

According to the answer from Ravi Teja (topic "C app and Python"), I
need to extend embedded python in my C application.

I saw several functions: PyRun_AnyFileEx Flags, PyRun_SimpleFil eExFlags,
PyRun_FileExFla gs.

1) Which one should i use in order to achieve what i need ?
2) I couldn't understand the differance betwwen the three ?
3) What is the difference between the "FILE *fp" and "const char
*filename" arguments of these functions. If i give a FILE*, why do i
need to give the file name ?


Jan 4 '07 #1
1 1782
"Vertilka" <ve******@gmail .comwrote:
I saw several functions: PyRun_AnyFileEx Flags, PyRun_SimpleFil eExFlags,
PyRun_FileExFla gs.

1) Which one should i use in order to achieve what i need ?
PyRun_SimpleFil e or PyRun_SimpleStr ing should be good enough. Using
SimpleString is more robust:


and also lets you implement additional glue in Python code instead of in C/C++.
2) I couldn't understand the differance betwwen the three ?
AnyFile supports interactive devices, RunFile requires you to provide a custom
execution context.
3) What is the difference between the "FILE *fp" and "const char
*filename" arguments of these functions. If i give a FILE*, why do i
need to give the file name ?
Python needs the filename to be able to give meaningful error messages.


Jan 4 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: satish | last post by:
Hello all, I have a shared object executable viz. *cable* which I execute as follows : $ ansyscust71 -custom cable -p ANSYSRF **ansyscust71 is a shell script and is a part of a software called ANSYS** Now, I have generated a python module using a *fortran-python interface
by: Anand K Rayudu | last post by:
Hi all, I have embedded python and want to execute python scripts from my application. I need to call the execution of python repeatedly, and some times same script again & again. I am facing some problems , especially if i try to execute the same script again. Some times in loading my module. Even it looks like for loops are not working, if i replace them with 'while' it worked. This is on windows system with python 2.3.3 , I have...
by: stefan | last post by:
Hi Folks, I currenty extended some of my C++ functionality to python and also embedded python to use python functionality in my C++ system (and use as well these extended functions). While this works fine with the core python functionality, as soon as I run a script (on the embedded system) which tries to import modules which are not in the core system, like "xml" or "re", it fails and says it cannot find the related dll (for example...
by: ch424 | last post by:
Hi there, I'm using Python 2.4.1 on Ubuntu Linux, and I'm having problems extending python in C: The C code is below: #include <Python.h> #include "ni488.h"
by: Richard Townsend | last post by:
In the "Extending and Embedding" part of the Python documentation: section 5.4 "Extending Embedded Python" - it describes how to use a Python extension module from Python that is embedded in a C application. Is it safe to call Py_InitModule() more than once in the same application - in order to be able to use more than one extension module? -- Richard
by: Torsten Bronger | last post by:
Hallöchen! I'd like to script C++ funtions by an embedded Python interpreter. So far, my C++ main() function contains: Py_Initialize(); Py_InitModule("pp3", PythonMethods); PyRun_SimpleString("from pp3 import *"); PyRun_AnyFile(stdin, NULL); Py_Finalize();
by: Carl Douglas | last post by:
Hi Python fans, I am developing a DLL that is loaded by a host application on windows. I'm using python 2.5. My DLL uses an embedded python interpreter which can access the host application through an API which I have exposed using SWIG 1.3.31. Therefore I have both extended and embedded Python at once: the SWIG generated code is statically linked into my DLL, and one of the
by: vishnu | last post by:
Hello All, I have embedded python 2.5 in to my C application. As we need the python scripts to run in multi threaded environment I have used Py_NewInterpreter() and Py_EndInterpreter each time I execute a run script function. The code is as follows: RunScript(char *pScriptName,char *pFuncName,...) { PyEval_AcquireLock()
by: dmoore | last post by:
Hi Folks: I have a question about the use of static members in Python/C extensions. Take the simple example from the "Extending and Embedding the Python Interpreter" docs: A simple module method: static PyObject * spam_system(PyObject *self, PyObject *args)
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.