[Pyparsing] pyparsing floats - still stuck
Brought to you by:
ptmcg
From: Donn I. <don...@gm...> - 2007-11-08 14:58:01
|
Hi, Still stuck. I am having trouble getting a float out of the parsed String. Here's a sample: from pyparsing import * 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) ) ) + Optional(command) d2=""" M 269.78326 , 381.27104 C 368.52151 , 424.27023 90.593578 , -18.581883 90.027729 , 129.28708 C 89.461878 , 277.15604 171.04501 , 338.27184 269.78326 , 381.27104 z """ pl = phrase.parseString(d2.upper()) for t in pl: for i in t: if len(i) == 1: print i if len(i)>1: for si in i: print "si",si, print "type(si):", type(si) print " float(si):", float(si) I need those values to be floats. What am I doing dumb? \d |