简体   繁体   中英

How to read text from a file using Python?

I have some header files in C that I want to read in Python. Is there a way to do this? For example, if I have a header file that contains the following code in C:

#define x 0x00
#define y 0x03
#define z 0x0003

Would I be able to extract this data using Python?

data = dict()
with open("file.h", "r") as f:
    for l in f:
        l = l.split(" ")
        data[l[1]] = l[2]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM