I’m trying to define a function (initdeque()) that takes a pointer to an instance of the deque class. So this is what I tried:
from ctypes import *
class deque(Structure):
pass
deque._fields_ = [("left",POINTER(node)),("right",POINTER(node))]
def initdeque(class deque *p):
p.left=p.right=None
But this code gives a syntax error:
def initdeque(class deque *p):
^
SyntaxError: invalid syntax
What is the correct syntax?
There is no way to specify the type of Python variables, so the declaration of
initdequeueshould just say:Instead of having a random function doing the initialization, you should consider using an initializer:
Now, to create a new instance, just write