Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7002351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:55:01+00:00 2026-05-27T20:55:01+00:00

I need a simple way to pass a C struct to a Python function.

  • 0

I need a simple way to pass a C struct to a Python function. I have embedded Python into a game server, and I intend to write game logic in Python. I’ve scoured Google and mailing lists and found nothing useful. I have a complex structure in C (with pointers to other relatively complex structures) and have found no reasonable way of doing this.

I have this struct:

struct client {
    int state;
    int sockfd;
    struct sockaddr_in *addr;
    struct epoll_event *epollev;
    struct buffer *in_buffer;
    struct buffer *out_buffer;
    struct packet *packet;
    struct player *player;
};

And need to pass it to a Python function where I can easily access the members with common syntax (preferably not the use of things like dicts although that’s alright too). It’s almost like I need a PyObject_FromStruct function or something.

Is there any relatively simple way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:55:02+00:00Added an answer on May 27, 2026 at 8:55 pm

    i think that the most simple way may be to write get()/set() functions for every element in the structure (ex: get_addr() which gets the address value) and then:

    Option 1 (i think it is the simplest) :compile your c code as dll file with get/set exported and load it into python to call “get” functions
    (check my post here for using dll in python and this Q&A may be useful for using .so files in linux

    Option 2 :you may use SWIG to get the pyd file and import it into python to call “get/set” functions

    using this way python is dealing only with pointee NOT pointers and do not involve any memory addresses usage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any simple way to do this or I need to pass by
I have this very simple login form with user and pass and I need
I need a simple way to monitor multiple text log files distributed over a
I need an simple way to check whether a string that is sent to
I need a robust and simple way to remove illegal path and file characters
Is there a simple way to check the type of an object? I need
I need to remove multiple items from a Dictionary. A simple way to do
i developed a very simple vb.net application and i need a way for every
There is some way to pass action in <rich:modalPanel> . I want to write
Is there any way to pass function as a parameter when starting a program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.