相关疑难解决方法(0)

ctypes结构中的默认值

在ctypes结构中,是否可以指定默认值?

例如,使用常规python函数,您可以这样做:

def func(a, b=2):
    print a + b
Run Code Online (Sandbox Code Playgroud)

这将允许这种行为:

func(1) # prints 3

func(1, 20) # prints 21

func(1, b=50) # prints 51
Run Code Online (Sandbox Code Playgroud)

是否可以在ctypes结构中执行此操作?

例如:

class Struct(Structure):
    _fields_ = [("a", c_int), ("b", c_int)] # b default should be 2

    def print_values(self):
        print self.a, self.b

struct_instance = Struct(1)

struct_instance.print_values() # should somehow print 1, 2
Run Code Online (Sandbox Code Playgroud)

python parameters ctypes default structure

7
推荐指数
2
解决办法
4599
查看次数

标签 统计

ctypes ×1

default ×1

parameters ×1

python ×1

structure ×1