Re: [Pyparsing] pyparsing svg - noob
Brought to you by:
ptmcg
From: Donn <don...@gm...> - 2007-11-08 11:34:35
|
Paul, Sorry to bug you. Two things: 1. I am having a conceptual issue with the "list" returned by parseString. I can't seem to use it as a normal list. Mainly I like to while len(l)>0: and then l.pop(0) to process it but I can't seem to pop this list. 2. It seems the optional closing "Z" is being ignored. dot = Literal(".") float = Combine(Optional("-") + Word(nums) + dot + Word(nums)) command = oneOf("M L C Z") comma = Literal(",").suppress() couple = Group(float + comma + float) phrase = OneOrMore(command + Group(OneOrMore(couple)) ) #No C commands in this one... d1="""M 209.12237,172.2415 L 286.76739,153.51369 L 286.76739,275.88534 L 209.12237,294.45058 L 209.12237,172.2415 z """ paths = [] pl = phrase.parseString(d1.upper()) while len(pl) > 0: something = pl.pop(0) print something (I get : TypeError: 'str' object is not callable) I could use <for something in pl:> but since some of the coord lists are longer than others and not grouped ideally, it gets hairy. The ideal grouping would be something like this (I mix C and L commands) ['M', [float,float], 'C',[float,float,float,float,float,float], 'L',[float,float], 'Z'] So I can just pop them off one by one. \d |