小编tot*_*ter的帖子

替换所有与正则表达式匹配的匹配项

我有一个正则表达式,搜索包含'.00.''.11.'如下的字符串:

.*\.(00|11)\..*
Run Code Online (Sandbox Code Playgroud)

我想做的是用'X00X'或替换所有与模式匹配的事件'X11X'.例如,字符串'.00..0..11.'将导致'X00X.0.X11X'.

我正在研究Python re.sub方法,并且不确定如何有效地执行此操作.返回的匹配对象仅在第一次出现时匹配,因此无法正常工作.有什么建议?我应该只使用字符串替换此任务吗?谢谢.

python regex

13
推荐指数
1
解决办法
3万
查看次数

从库返回的 ctypes 结构

给定一个简单的 C 文件:

#include <stdio.h>

typedef struct point {
    int x;
    int y;
} POINT; 

POINT get_point() 
{
    POINT p = {1, 2};
    return p;
}
Run Code Online (Sandbox Code Playgroud)

我有一个简单的 python 文件:

from ctypes import *
import os

lib_name = '/testlib.so' 
test_lib = CDLL(os.getcwd() + lib_name)

class POINT(Structure):
    _fields_ = [('x', c_int),
                ('y', c_int)]

# Sets p1 to the integer 1
p1 = test_lib.get_point()
# Sets p2 to the struct POINT with values {1, 0}
p2 = POINT(test_lib.get_point())
Run Code Online (Sandbox Code Playgroud)

如何将返回值设置为POINT带有 value 的结构 …

c python ctypes wrapper python-2.7

7
推荐指数
1
解决办法
6356
查看次数

标签 统计

python ×2

c ×1

ctypes ×1

python-2.7 ×1

regex ×1

wrapper ×1