Newsgroups: comp.lang.python
From: Paul McGuire <pt...@austin.rr.com>
Date: Fri, 13 Mar 2009 13:21:45 -0700 (PDT)
Local: Fri, Mar 13 2009 4:21 pm
Subject: Re: converting a string to a function parameter
On Mar 13, 11:46 am, Aaron Brady <castiro...@gmail.com> wrote:
> On Mar 13, 2:52 am, koranthala <koranth...@gmail.com> wrote: Did someone say 'pyparsing'? :) Here is a first cut (partially lifted > > Hi, > > I tried eval, but it did not work. And any other mechanism I think > > Is there any mechanism with which we can do this straight away? > I heard 'pyparsing' was good. ...Not that I've even been to its from a previous post): from pyparsing import * LPAR,RPAR,LBRACK,RBRACK,EQ,COMMA = map(Suppress,"()[]=,") noneLiteral = Literal("None") ident = Word(alphas+"_",alphanums+"_") listStr = Forward().setName("list") # parse actions perform parse-time conversions arg = Group(ident("varname") + EQ + listItem("varvalue")) | listItem argstring = 'True, type=rect, sizes=[3, 4,], coords = ([1,2],[3,4])' parsedArgs = delimitedList(arg).parseString(argstring) print "Args:", args Prints: Args: [True] You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
