from bge import logic
def test(cont):
if not hasattr(logic, "variable"):
logic.variable = 1
The hasattr function checks If the module logic (or bge) (the first argument) doesn’t have a function or attribute named “variable” (the second argument), it return True or False.
Why do you import gamelogic and bge? AFAIK, They are the same thing.