I am running into an issue I cannot seem to resolve. I have created a Python package containing amongst many things a function inside a class that sends a query to a database and retrieves the results. I also have a seperate program that uses that function. The whole thing looks like this:
Oddjob
(seperate python module):
def query(self, query):
"""
Running a query against Oddjob and returning result
:param query: The query to run
:return:
"""
try:
qr = self.c.execute(query)
qry = self.c.fetchall()
except Exception, e:
qry = e
return qry
This ^^^ is what is being called.
The query that needs to be run is kept in a variable as such:
sAvail = "exec sp_avi @week='32'"
And gets called like this:
SAvailability(oddjob.query(str(sAvail)))
Just for information, SAvailability is this code:
def SAvailability(result):
shipped = result[0]
onhold = result[1]
percentWO = 100 / int(shipped)
percentOnHold = percentWO * int(onhold)
total = str(int(math.floor(100 - percentOnHold)))
return total
Please note however, I provide the SAvailability function only for clarification, when I use query together with another function I get the same problem:
TypeError: 'str' object is not callable
The full traceback is:
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/arthur/Dropbox/Scaramanga_Development/scaramanga/server.py", line 1062, in dashboard_HEAD
SAvailability(oddjob.query(str(sAvail))),
TypeError: 'str' object is not callable
I have tried adding str() left, right, and centre, but nothing seems to change it. Can anyone see anything obvious I am missing?