[error] TypeError ( 'int' object is not callable )

Asked by arminius on 2017-07-07

centerX = 607
ml = Env.getMouseLocation()
total = ml.getX+centerX()
print total()

But I get the error message that is in the Summary, what does it mean by int?

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
2017-07-09
Last query:
2017-07-09
Last reply:
2017-07-08
Manfred Hampl (m-hampl) said : #1

What is centerX - a function or an integer variable?
It it is an int, then you must not add brackets "()"
and the same for total.

arminius (arminius75) said : #2

ok, I got rid of the brackets.
so now it's "ml = Env.getMouseLocation()
total = ml.getX+centerX
print ml.getX()
print total"

now it's returning "[error] TypeError ( unsupported operand type(s) for +: 'instancemethod' and 'int' )"

Manfred Hampl (m-hampl) said : #3

You need to get better in python basics.

You have to understand the difference between using variables (no brackets) and calling functions (need brackets).

Look at your code:
...
total = ml.getX+centerX
print ml.getX()
...
In the second line ml.getX has brackets, but in the first line it hasn't.
This cannot be correct in python syntax.

I assume the correct statements are

ml = Env.getMouseLocation()
total = ml.getX() + centerX
print ml.getX
print total

Best Manfred Hampl (m-hampl) said : #4

Oops, sorry, now I ommitted brackets, it must of course be

ml = Env.getMouseLocation()
total = ml.getX() + centerX
print ml.getX()
print total

arminius (arminius75) said : #5

Thanks Manfred Hampl, that solved my question.