我试图将python程序嵌入C程序中。我的操作系统是Ubuntu 14.04
我尝试将python 2.7和python 3.4解释器嵌入到同一C代码库中(作为单独的应用程序)。嵌入python 2.7时,编译和链接有效,但不嵌入python 3.4。在链接器阶段失败。
这是我的C代码(只是一个示例,不是真实代码)
简单的
#include <stdio.h>
#include <Python.h>
int main(int argc, char *argv[])
{
PyObject *pName, *pModule, *pFunc, *pValue;
char module[] = "get_version";
char func[] = "get_version";
char module_path[] = ".";
Py_Initialize();
PyObject *sys_path = PySys_GetObject("path");
PyList_Append(sys_path, PyUnicode_FromString(module_path));
pName = PyUnicode_FromString(module);
pModule = PyImport_Import(pName);
Py_DECREF(pName);
if(pModule != NULL)
{
pFunc = PyObject_GetAttrString(pModule, func);
if (pFunc && PyCallable_Check(pFunc))
{
pValue = PyObject_CallObject(pFunc, NULL);
if (pValue != NULL) {
printf("Python version: %s\n", PyString_AsString(pValue));
Py_DECREF(pValue);
}
else { …Run Code Online (Sandbox Code Playgroud) 我正在尝试为开发人员编写ansible playbooks并为django应用程序测试env配置.然而,在ansible任务中使用条件时似乎存在问题.
在下面的代码中,任务2在任务1被更改时执行.它不检查第二个条件.
- name: Task 1
become: yes
command: docker-compose run --rm web python manage.py migrate chdir="{{ server_code_path }}"
when: perform_migration
register: django_migration_result
changed_when: "'No migrations to apply.' not in django_migration_result.stdout"
tags:
- start_service
- django_manage
- name: Task 2 # Django Create Super user on 1st migration
become: yes
command: docker-compose run --rm web python manage.py loaddata create_super_user_data.yaml chdir="{{ server_code_path }}"
when: django_migration_result|changed and ("'Applying auth.0001_initial... OK' in django_migration_result.stdout")
ignore_errors: yes
tags:
- start_service
- django_manage
Run Code Online (Sandbox Code Playgroud)
每当更改Task1而不评估第二个条件时,就会运行任务2
"'Applying …Run Code Online (Sandbox Code Playgroud)