Linked Questions

28 votes
4 answers
102k views

I am going to define a structure and pass it into a function: In C: struct stru { int a; int b; }; s = new stru() s->a = 10; func_a(s); How this can be done in Python?
Bin Chen's user avatar
  • 63.7k
8 votes
1 answer
34k views

I have this C code: typedef struct test * Test; struct test { void *a; Test next; }; How would you implement the equivalent to this in Python (if that is even possible)?
user1790813's user avatar
0 votes
2 answers
729 views

I am looking for fixed keys, like a namedtuple, but mutable values like a dict. I would probably have used a struct in C. Is there such a data structure in Python?
Thomas Arildsen's user avatar
3 votes
0 answers
369 views

I am having a bitfield structure in C and i want to implement the same in python. With the structure i am having in C i am able to get 2 byte of data through it..and i write this data in a file in ...
Akshat Pant's user avatar
1 vote
0 answers
86 views

Could any one help me to implement C structure data type in python? I need a similar structure data type in python as below. struct msgbuf { long mtype; char mtext[100]; };
Winner's user avatar
  • 23
1305 votes
14 answers
442k views

What is the purpose of __slots__ in Python — especially with respect to when I would want to use it, and when not?
Jeb's user avatar
  • 17.2k
437 votes
34 answers
388k views

I find it more convenient to access dict keys as obj.foo instead of obj['foo'], so I wrote this snippet: class AttributeDict(dict): def __getattr__(self, attr): return self[attr] def ...
Izz ad-Din Ruhulessin's user avatar
19 votes
9 answers
40k views

I wanted to create a throwaway "struct" object to keep various status flags. My first approach was this (javascript style) >>> status = object() >>> status.foo = 3 Traceback (most ...
Stefano Borini's user avatar
9 votes
8 answers
1k views

I've been trying to port this code to python, but there is something I do not quite understand in C++ (I do know a bit of C++ but this is beyond me): typedef struct huffnode_s { struct huffnode_s ...
Douglas's user avatar
  • 91
4 votes
2 answers
4k views

I am making a terminal game using Python's wonderful Cmd library. But i was curious if i could somehow put argparse code into it. Like use argparse to handle the 'args' from my cmd.Cmd() class. To do ...
Kieee's user avatar
  • 136
3 votes
4 answers
2k views

I'm creating a dictionary d of one million of items which are tuples, and ideally I'd like to access them with: d[1634].id # or d[1634]['id'] d[1634].name # or d[1634]['name'] d[1634]....
Basj's user avatar
  • 48k
2 votes
4 answers
1k views

I have three variables that are closely tied together and I do not want to pass separately every time I call a function. What is the proper way to bundle them. Context: The purpose of the variables ...
Ottotos's user avatar
  • 673
-2 votes
2 answers
5k views

Currently I am porting a pascal program to python, and there I have the following code: ScanList = Record name : string; I : Integer; ...
arc_lupus's user avatar
  • 4,156
-3 votes
1 answer
2k views

c++ type structure example: Struct xyz { uint64_t a; uint32_t b; uint16_t c; bool d; char e; } var; where I can access it using var.a = 1; var.b = 2, and so on... Here I have ...
ronex dicapriyo's user avatar
3 votes
3 answers
697 views

I wrote a program in C that uses structs to model the motion of planets going around the Sun. I want to write that same program in Python. The planets and Sun are treated as particles. In C I wrote ...
user3650942's user avatar

15 30 50 per page