The second one allows interactive communication, which might be useful later. He also pointed me to the manual page of "system" and "popen". It crashes only with this function, if I call PyRunSimpleString it works. I didn't want to edit the old post because these two programs are entirely new approaches One in C and one in C . Hello metin2dev, bascially, I am writting a Python Loader thats work with Python 2.7.3 but I have a problem: when I call the function PyRunSimpleFile it crashes. Free simplefiles torrent download download software at UpdateStar - 1,746,000 recognized programs - 5,228,000 known versions - Software News. *Grumble, took me over 2 hours to format this text so I could post it.*Ī friend of mine gave me some code snippets which answer the problem. Return (a if min(a) < min(b) else b)#they get compared and returned to the c-program def compare_function(a, b):#this function takes 2 parameters, they are strings Printf("Error: No script file named \"script.py\" was found!\n") 10 Most Popular Torrent Sites of 2023 TorrentFreak Top 10 Most Popular Torrent Sites of 2023 Januby Ernesto Van der Sar Home > Piracy > Torrent Sites > Continuing a. Torrents become a savior when every service exploits users’ demands by offering premium services. Nonetheless, you must use a robust antivirus and a VPN to remain safe out of caution. Printf("The Script decdided that '%s' is longer!",result) We have gathered the best torrent sites in this guide that offer safe and reliable content to ease things for you. but luckily there's a function to cast it back to a c-compatible char*! Ret = PyObject_CallObject(func, prm) //Returns some python object i have literally no idea about. Prm = Py_BuildValue("(ss)", "Hello", "Mars") //The "(ss)" means two strings are passed (replace with "i" for integer for instance), the "Hello" and "Mars" are the strings i pass to the script. Notice that you must use a function within the python script, because otherwise you can't return anything. If (module != 0)//Asks if the script was loaded at all.įunc = PyObject_GetAttrString(module, "compare_function") //Opens a function within the python script. Module = PyImport_ImportModule("script") //Import of the script-file, note that the actual script name is "script.py"! PySys_SetPath(".") //Sets the working path to the current path PyObject *module, *func, *prm, *ret //These are some helping variables i don't understand. bugs, grammar mistakes and wrong explainations are my contributionĬhar *result //This char will receive the return value. Translation from german with many additional (and very unprofessional) comments and slight adaption by Cupacoffee. owner is Peter Kaiser and Johannes Ernesti who published the Book "Python" under Galileo Computing compile me with "gcc main.c -I/usr/include/python2.7 -lpython2.7" I still find it strange that it takes ~20 commands to achieve this, maybe there's a better solution out there. It consists of 2 files: "main.c" that opens the script-file "script.py" which compares two strings (here: "Hello" and "Mars") and returns the longer one. I made both C and Python read and write into a file.
0 Comments
Leave a Reply. |