Skip to content

Instantly share code, notes, and snippets.

@lighth7015
Created February 7, 2020 20:47
Show Gist options
  • Save lighth7015/f35bae8720854eee0b4b7ec42aeef5d0 to your computer and use it in GitHub Desktop.
Save lighth7015/f35bae8720854eee0b4b7ec42aeef5d0 to your computer and use it in GitHub Desktop.
import re, os.path as path
class Makefile(object):
def __init__(self, filename):
if path.exists(filename):
self.handle = open(filename)
def get(self, name, default = None):
value = default
for it in self.handle.readlines():
if len(line := it.strip()) > 0:
if line[0] != '#':
print(list(tuple(it) for it in re.split( r".?=|##", line ) if len(line) > 0))
#result = [tuple(key.strip(), value.strip()) for key, value in list( it for it in re.split( r"[\?:]=|##", line ))]
#print(result)
return value
makefile = Makefile("global.cfg")
makefile.get("")
# generated file, do not edit!
BUILDCFG ?= release
DEFAULT_CFLAGS := -std=c99
DEFAULT_CC=clang

Traceback

Traceback (most recent call last):
  File "lib/sdk/FileType.py", line 28, in <module>
    makefile.get("")
  File "lib/sdk/FileType.py", line 15, in get
    print(list(tuple([ key.strip(), value.strip() ]) for key, value in re.split( r"[\?:]?=|##", line ) if len(line) > 0))
  File "lib/sdk/FileType.py", line 15, in <genexpr>
    print(list(tuple([ key.strip(), value.strip() ]) for key, value in re.split( r"[\?:]?=|##", line ) if len(line) > 0))
ValueError: too many values to unpack (expected 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment