I want to convert a head file which is written in C to a class in python
Basically, the format of the head file in C (a file called header.c is like following:
#define ATTR_A (HELLO +1L) /*FSDSDF*/
#define ATTR_B (HELLO +2L) /*FSFSSF*/
What I want to do is writing a simple script which can read the text from header.c and then convert the format to a python calss and stored the result to a file called header.py. After conversion, it will be:
ATTR_A = (HELLO +1L)
ATTR_B = (HELLO +2L)
I know how to read the file and how to store the converted result into header.py, but I know how to do the conversion. Can someone please help me? Thanks!
I think the best way to do this is using
rehere.(\w*)is used to extract the ‘ATTR_A’(\s*)is used to extract the whitespacesInside
(\(.*\)),\(actually matches(and\)mataches)..*matches any character except a newline.So, after the
split,r= ['', 'ATTR_A', ' ', '(HELLO +1L)', ' /*FSDSDF*/'], which a list.