Defining a Python enum in a C extension - am I doing this right?

Schachner, Joseph Joseph.Schachner at Teledyne.com
Fri Jul 30 13:33:36 EDT 2021


Instead of struggling to define an enum  in C that can be read in Python - I'm assuming you can pass strings back and forth - why not just print whatever you need to give to Python into a string (or maybe 2 strings) and send it to Python as string?   Python is a dynamic language, it can quickly build an enum  type from one string and instantiate enums of that type from the other string.  

In short, if you have problems creating an enum in C and passing it to Python, give the problems to Python! Let it create the enum.

--- Joseph S.


Teledyne Confidential; Commercially Sensitive Business Data

-----Original Message-----
From: Serhiy Storchaka <storchaka at gmail.com> 
Sent: Friday, July 30, 2021 4:22 AM
To: python-list at python.org
Subject: Re: Defining a Python enum in a C extension - am I doing this right?

23.07.21 11:20, Bartosz Golaszewski пише:
> I'm working on a Python C extension and I would like to expose a 
> custom enum (as in: a class inheriting from enum.Enum) that would be 
> entirely defined in C.

I think that it would be much easier to define it in Python, and then either import a Python module in your C code, or exec a Python code as a string.



More information about the Python-list mailing list