adriank / ObjectPath

The agile query language for semi-structured data
http://objectpath.org
MIT License
380 stars 93 forks source link

Jupyter Notebook, py2.7 get errors on tutorial #44

Closed AnneTheAgile closed 7 years ago

AnneTheAgile commented 8 years ago

I wish to use a python notebook, ie jupyter with this library. I could only get the most trivial example to work. Any ideas? thank you! Anne

This works, returning '1' http://objectpath.org/tutorial.html

from objectpath import *
tree1=Tree({"a":1})
tree1.execute("$.a")

None of the complex json example is working;

json3 = '{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 } ] }}'
tree3=Tree(json3)
tree3.execute("$")  # ("$.store.book[0].price")

/Users/ME/anaconda/envs/py27/lib/python2.7/site-packages/objectpath/core/interpreter.pyc in execute(self, expr)
    603                 D=self.D
    604                 if type(expr) in STR_TYPES:
--> 605                         tree=self.compile(expr)
    606                 elif type(expr) not in (tuple,list,dict):
    607                         return expr

/Users/ME/anaconda/envs/py27/lib/python2.7/site-packages/objectpath/core/interpreter.pyc in compile(self, expr)
     36                 if expr in EXPR_CACHE:
     37                         return EXPR_CACHE[expr]
---> 38                 ret=EXPR_CACHE[expr]=parse(expr,self.D)
     39                 return ret
     40 

/Users/ME/anaconda/envs/py27/lib/python2.7/site-packages/objectpath/core/parser.pyc in parse(expr, D)
    462                 nextToken=tokenize(expr).next
    463         token=nextToken()
--> 464         r=expression().getTree()
    465         if D:
    466                 print ("PARSE STAGE")

/Users/ME/anaconda/envs/py27/lib/python2.7/site-packages/objectpath/core/parser.pyc in expression(rbp)
    443         t=token
    444         token=nextToken()
--> 445         left=t.nud()
    446         while rbp < token.lbp:
    447                 t=token

/Users/ME/anaconda/envs/py27/lib/python2.7/site-packages/objectpath/core/parser.pyc in nud(self)
    276         else:
    277                 self.fst=token.value
--> 278                 advance()
    279         return self
    280 

/Users/ME/anaconda/envs/py27/lib/python2.7/site-packages/objectpath/core/parser.pyc in advance(ID)
    159         if ID and token.id != ID:
    160                 raise SyntaxError("Expected %r, got %s"%(ID,token.id))
--> 161         token=nextToken()
    162 
    163 def method(s):

StopIteration: 

I am using;

$ source activate py27; 
discarding /Users/ME/anaconda/bin from PATH
prepending /Users/ME/anaconda/envs/py27/bin to PATH
$ python --version ; pip --version 
Python 2.7.11 :: Continuum Analytics, Inc.
pip 8.1.2 from /Users/ME/anaconda/envs/py27/lib/python2.7/site-packages (python 2.7)
$ ipython --version ; jupyter --version 
4.2.0
4.1.0
adriank commented 8 years ago

Hi,

$ alone is not a proper OP expression. Could you please send me log of tree3.execute("$.store.book[0].price")?

Have you tried to run the code from bare Python 2.7?

Greetings, Adrian Kalbarczyk

http://kalbarczyk.co http://about.me/akalbarczyk

On Thu, Jun 16, 2016 at 4:30 AM, AnneTheAgile notifications@github.com wrote:

I wish to use a python notebook, ie jupyter with this library. I could only get the most trivial example to work. Any ideas? thank you! Anne

This works, returning '1'

from objectpath import * tree1=Tree({"a":1}) tree1.execute("$.a")

None of the complex json example is working;

json3 = '{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 } ] }}' tree3=Tree(json3) tree3.execute("$") # ("$.store.book[0].price")

/Users/ME/anaconda/envs/py27/lib/python2.7/site-packages/objectpath/core/interpreter.pyc in execute(self, expr) 603 D=self.D 604 if type(expr) in STR_TYPES: --> 605 tree=self.compile(expr) 606 elif type(expr) not in (tuple,list,dict): 607 return expr

/Users/ME/anaconda/envs/py27/lib/python2.7/site-packages/objectpath/core/interpreter.pyc in compile(self, expr) 36 if expr in EXPR_CACHE: 37 return EXPR_CACHE[expr] ---> 38 ret=EXPR_CACHE[expr]=parse(expr,self.D) 39 return ret 40

/Users/ME/anaconda/envs/py27/lib/python2.7/site-packages/objectpath/core/parser.pyc in parse(expr, D) 462 nextToken=tokenize(expr).next 463 token=nextToken() --> 464 r=expression().getTree() 465 if D: 466 print ("PARSE STAGE")

/Users/ME/anaconda/envs/py27/lib/python2.7/site-packages/objectpath/core/parser.pyc in expression(rbp) 443 t=token 444 token=nextToken() --> 445 left=t.nud() 446 while rbp < token.lbp: 447 t=token

/Users/ME/anaconda/envs/py27/lib/python2.7/site-packages/objectpath/core/parser.pyc in nud(self) 276 else: 277 self.fst=token.value --> 278 advance() 279 return self 280

/Users/ME/anaconda/envs/py27/lib/python2.7/site-packages/objectpath/core/parser.pyc in advance(ID) 159 if ID and token.id != ID: 160 raise SyntaxError("Expected %r, got %s"%(ID,token.id)) --> 161 token=nextToken() 162 163 def method(s):

StopIteration:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/adriank/ObjectPath/issues/44, or mute the thread https://github.com/notifications/unsubscribe/AAKycsSKQnDBiWVX3ILjYID_j7ZQ5yYAks5qMLVOgaJpZM4I2-Gm .