How to set global variables from methods or function?

Asked by Jeff Sant

Here is my code in which i am getting error

value_not_found=0

def value_not_found():
 global value_not_found
 value_not_found=1

def valuefound():
 global value_not_found
        value_not_found=0

i call the function in another function def:

def check_value_found:
        value_not_found()

When i try to call a function i get this error:

TypeError: 'int' object is not callable

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Jeff Sant
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

The def's do not make sense:

instead of:

def value_not_found():
 global value_not_found
 value_not_found=1

def valuefound():
 global value_not_found
 value_not_found=0

do it this way:

def value_not_found():
 return False

def value_found():
 return True

usage:

if value_found():
   # do something

nevertheless, your problem in your version is:

value_not_found=0
def value_not_found():
 global value_not_found

you use the same name for different things and
with the last definition (global ... ) counts and makes it an integer that is not callable, as the message tells you.

Pls. learn some Python and consult the docs, before asking trivial things.

Last time - now public: I miss your feedback !
If you do not give back, I will stop answering, sorry.

Revision history for this message
Jeff Sant (sant-jeff) said :
#2

Dear Raiman,

This resolved my issues, thank you so much for always putting an extra effort to solve our issues.

Thanks