Code: Alles auswählen
from collections import namedtuple
TEST_TEXT = """\
# ImageMagick pixel enumeration: 300,168,255,srgb
0,0: (23, 22, 2 ) #171602 srgb(23,22,2)
1,0: (34,33, 13) #22210D srgb(34,33,13)
2,0: ( 18,20 ,0 ) #121400 srgb(18,20,0)
3,0: ( 32,34 , 13) #20220D srgb(32,34,13)"""
RGBColor = namedtuple('RGBColor', 'r,g,b')
def parse_rgb(line):
start = line.index('(') + 1
stop = line.index(')', start)
r, g, b = (
int(digits) for digits in line[start:stop].split(',')
)
return RGBColor(r, g, b)
def main():
for line in TEST_TEXT.splitlines():
if not line.startswith('#'):
print(parse_rgb(line))
if __name__ == '__main__':
main()