check for global variable?

I’ve use code like this:

import bge

def test(cont):

    own = cont.owner
    if not "variable" in own:
        own["variable"] = 1

but I don’t know what to do with global variables. I’ve tried things like this:

import bge
import GameLogic

g = GameLogic

def test(cont):

    if not "variable" in g:

       g.variable = 1

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.

EDIT: gamelogic is bge.logic

I dunno. I probably learned it from an old guide. it’s one of the problems of being self taught. I sometimes pick up outdated information.