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 5950351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:22:52+00:00 2026-05-22T17:22:52+00:00

I have a structure with different datatype fields. I would like to iterate through

  • 0

I have a structure with different datatype fields. I would like to iterate through the structure fields, check the datatype, and set the field with an appropriate value.

I have access to the size and offset of the field through the .size and .offset attribute of the field. How can I get the ‘type’ attribute of the field? Using type(value) does not print the ctypes datatype for the particular field. If I print value then I do see the ctypes datatype but there doesn’t seem to be an attribute to access this directly.

How can I access the type field descriptor directly?

from ctypes import *

class A(Structure):
    _fields_ = [("one", c_long),
                ("two", c_char),
                ("three", c_byte)]

>>> A.one
<Field type=c_long, ofs=0, size=4>
>>> A.one.offset
0
>>> A.one.size
4
>>> type(A.one)
<class '_ctypes.CField'>

Ideally I would like to get the field type similar to the snippet below…

>>> A.one.type
c_long
  • 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-22T17:22:53+00:00Added an answer on May 22, 2026 at 5:22 pm

    Just use the _fields_ list:

    >>> for f,t in A._fields_:
    ...  a = getattr(A,f)
    ...  print a,a.offset,a.size,t
    ...
    <Field type=c_long, ofs=0, size=4> 0 4 <class 'ctypes.c_long'>
    <Field type=c_char, ofs=4, size=1> 4 1 <class 'ctypes.c_char'>
    <Field type=c_byte, ofs=5, size=1> 5 1 <class 'ctypes.c_byte'>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an input, which can have different structure. I would like to test
Is it possible to have a C++ template function which can access different fields
I have the option of writing two different formats for a database structure: Article
I have a structure like this: <ul> <li>text1</li> <li>text2</li> <li>text3</li> </ul> How do I
I have a structure like this.... UITableViewController -> UITableViewCell -> UIView I need the
I have a C structure that looks like this typedef struct event_queue{ Event* event;
I have two databases with different structure. Table 1: ch_code ch_def ch_weight Table 2:
Hey guys. I have a question. I have two different arrays with different structure
I have three dataframes with this structure (but different values): V1 V2 2010-04-30 30
Let's say you have two arrays of arrays with the same structure but different

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.