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 <storch...@gmail.com> 
Sent: Friday, July 30, 2021 4:22 AM
To: python-list@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.

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to