TypeError: 'OneOrMore' object is not iterable

Ryan
2013-07-14
2013-07-17
  • Ryan

    Ryan - 2013-07-14

    I have this code:

    teststr = '(\"Hello!\", \"Hi!\")'
    args = Word(chars) + Optional(',' + OneOrMore(Word(chars)))
    print args.parseString(teststr)
    

    I am getting:

    TypeError: 'OneOrMore' object is not iterable

    I am clueless as to what is giving this error. The output should be:

    ['"Hello!"', '"Hi!"']

     
    • Paul McGuire

      Paul McGuire - 2013-07-17

      I think the error is with your definition of chars, but you are also trying
      to parse only the contents within the ()'s and so you will trip over the
      ()'s as well.

      This works:

      chars = alphanums+'!"'

      args = Word(chars) + Optional(',' + OneOrMore(Word(chars)))

      print (('('+args+')').parseString(teststr))

      Also, it is not necessary to escape "s when inside a quoted string delimited
      with 's. Write teststr simply as:

      teststr = '("Hello!", "Hi!")'

      Since your values in the tuple are quoted strings, a better expression would
      be:

      args = quotedString + ZeroOrMore(',' + quotedString)

      And in fact, this pattern is so common, that pyparsing defines the
      delimitedList helper method, so you can just write:

      args = delimitedList(quotedString)

      HTH,

      -- Paul

      From: Ryan [mailto:kirbyfan64sos@users.sf.net]
      Sent: Sunday, July 14, 2013 11:05 AM
      To: [pyparsing:discussion]
      Subject: [pyparsing:discussion] TypeError: 'OneOrMore' object is not
      iterable

      I have this code:

      teststr = '(\"Hello!\", \"Hi!\")'
      args = Word(chars) + Optional(',' + OneOrMore(Word(chars)))
      print args.parseString(teststr)

      I am getting:

      TypeError: 'OneOrMore' object is not iterable

      I am clueless as to what is giving this error. The output should be:

      ['"Hello!"', '"Hi!"']


      TypeError: 'OneOrMore' object is not iterable
      https://sourceforge.net/p/pyparsing/discussion/337293/thread/0a7105dc/?limi t=25#2ce4


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/pyparsing/discussion/337293/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks