In una struttura ctypes, è possibile specificare valori predefiniti?Valori predefiniti in un ctypes Struttura
Ad esempio, con una funzione di pitone regolare, si può fare questo:
def func(a, b=2):
print a + b
che permetterebbe di questo comportamento:
func(1) # prints 3
func(1, 20) # prints 21
func(1, b=50) # prints 51
E 'possibile farlo in una struttura ctypes?
ad esempio:
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
Grazie! Non sono sicuro del perché non ci ho pensato. :) –