I am now happily using BaseX from Jupyter Notebooks for Greek data - see these links:
http://jonathanrobie.biblicalhumanities.org/blog/2017/12/08/jupyter-tutorial... http://jonathanrobie.biblicalhumanities.org/assets/greeksyntax-tutorial-proi...
But I need to know how to handle exceptions, e.g. if the notebook user writes a query with an error in it. And I would also like to return some result if the query returns an empty sequence. Here is the current code:
https://github.com/biblicalhumanities/greek-new-testament/blob/master/labnot...
How can I improve what I am doing?
Jonathan
http://jonathanrobie.biblicalhumanities.org/blog/2017/12/08/jupyter-tutorial... http://jonathanrobie.biblicalhumanities.org/assets/greeksyntax-tutorial-proi...
Looks good!
But I need to know how to handle exceptions, e.g. if the notebook user writes a query with an error in it.
Have you tried to play around with try/except [1]? Well, there are surely other BaseX users out there that have more experience with Python.
Thanks! The try/except part is the part I understand. The part I don't understand is how to find the exception thrown by BaseX, I want to show syntax errors in a user friendly way like what you see in the GUI so people don't always have to go back to the GUI to figure out what's wrong with their queries.
Jonathan
On Tue, Dec 19, 2017 at 11:02 AM, Christian Grün christian.gruen@gmail.com wrote:
2017/12/08/jupyter-tutorial/
greeksyntax-tutorial-proiel.html
Looks good!
But I need to know how to handle exceptions, e.g. if the notebook user writes a query with an error in it.
Have you tried to play around with try/except [1]? Well, there are surely other BaseX users out there that have more experience with Python.
OK, I did the obvious and examined the exception, which is apparently an OSError. So this code works well:
def xquery(self, query): try: result = self.session.query(query).execute() except OSError as err: print("Error:", err) else: return result
e.g. if I do this call:
q.xquery("7 + 3 = <num>10</num")
I get this output:
Error: Stopped at ., 1/21: [XPST0003] Expecting '>'.
Posting here in case someone else finds it helpful.
Thanks!
Jonathan
On Tue, Dec 19, 2017 at 11:41 AM, Jonathan Robie jonathan.robie@gmail.com wrote:
Thanks! The try/except part is the part I understand. The part I don't understand is how to find the exception thrown by BaseX, I want to show syntax errors in a user friendly way like what you see in the GUI so people don't always have to go back to the GUI to figure out what's wrong with their queries.
Jonathan
On Tue, Dec 19, 2017 at 11:02 AM, Christian Grün < christian.gruen@gmail.com> wrote:
http://jonathanrobie.biblicalhumanities.org/blog/2017/12/08/
jupyter-tutorial/
http://jonathanrobie.biblicalhumanities.org/assets/greeksynt
ax-tutorial-proiel.html
Looks good!
But I need to know how to handle exceptions, e.g. if the notebook user writes a query with an error in it.
Have you tried to play around with try/except [1]? Well, there are surely other BaseX users out there that have more experience with Python.
Thanks for the update!
On Thu, Dec 21, 2017 at 7:30 PM, Jonathan Robie jonathan.robie@gmail.com wrote:
OK, I did the obvious and examined the exception, which is apparently an OSError. So this code works well:
def xquery(self, query): try: result = self.session.query(query).execute() except OSError as err: print("Error:", err) else: return result
e.g. if I do this call:
q.xquery("7 + 3 = <num>10</num")
I get this output:
Error: Stopped at ., 1/21: [XPST0003] Expecting '>'.
Posting here in case someone else finds it helpful.
Thanks!
Jonathan
On Tue, Dec 19, 2017 at 11:41 AM, Jonathan Robie jonathan.robie@gmail.com wrote:
Thanks! The try/except part is the part I understand. The part I don't understand is how to find the exception thrown by BaseX, I want to show syntax errors in a user friendly way like what you see in the GUI so people don't always have to go back to the GUI to figure out what's wrong with their queries.
Jonathan
On Tue, Dec 19, 2017 at 11:02 AM, Christian Grün christian.gruen@gmail.com wrote:
http://jonathanrobie.biblicalhumanities.org/blog/2017/12/08/jupyter-tutorial...
http://jonathanrobie.biblicalhumanities.org/assets/greeksyntax-tutorial-proi...
Looks good!
But I need to know how to handle exceptions, e.g. if the notebook user writes a query with an error in it.
Have you tried to play around with try/except [1]? Well, there are surely other BaseX users out there that have more experience with Python.
basex-talk@mailman.uni-konstanz.de