Does pyparsing support UNICODE strings?

Robert Kern rkern at ucsd.edu
Thu Aug 4 04:19:13 EDT 2005


could ildg wrote:
> pyparsing is very convenient to use. But I want to find some a py tool
> to parse non-English strings. Does pyparsing support UNICODE strings?
> If not, can someone tell me what py tool can do it? Thanks in advance.

Try it!

# vim:fileencoding=utf-8

from pyparsing import Word

text = "Καλημέρα, κόσμε!".decode('utf-8')
alphas = u''.join(unichr(x) for x in xrange(0x386, 0x3ce))

greet = Word(alphas) + u',' + Word(alphas) + u'!'
greeting = greet.parseString(text)
print greeting

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list