ctypes: return a pointer to a struct

sturlamolden sturlamolden at yahoo.no
Thu Apr 24 23:15:54 EDT 2008


On Apr 25, 5:09 am, "Jack" <nos... at invalid.com> wrote:

> typedef struct
> {
>  char *country_short;
>  char *country_long;
>  char *region;
>  char *city;
>  char *isp;
>  float latitude;
>  float longitude;
>  char *domain;
>  char *zipcode;
>  char *timezone;
>  char *netspeed;
>
> } IP2LocationRecord;


First define a struct type IP2LocationRecord by subclassing from
ctypes.Structure. Then define a pointer type as
ctypes.POINTER(IP2LocationRecord) and set that as the function's
restype attribute. See the ctypes tutorial or reference for details.









More information about the Python-list mailing list