W strukturze ctypes, czy możliwe jest określenie wartości domyślnych?Wartości domyślne w ctypes Struktura
Na przykład, z regularnym funkcji Pythona, można to zrobić:
def func(a, b=2):
print a + b
Pozwoliłoby tego zachowania:
func(1) # prints 3
func(1, 20) # prints 21
func(1, b=50) # prints 51
Czy to możliwe, aby to zrobić w strukturze ctypes?
na przykład:
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
Dzięki! Nie wiem, dlaczego o tym nie myślałem. :) –