how can I share variables between glsl and python in the bge? I am currently writing a glsl shader in the bge,

My question is, if I have glsl embedded into my python script, how can I if possible share memory/variables between my glsl and my python so the below is both valid and functioning.

I would like it so that i in f is the same as the i in the for loop. 

print("creating shads")
FragmentShaders = []

for i in range(257):
    f = """        
        varying vec4 maps[256];
        void main()
       {
          gl_FragColor = maps[i];//this is not valid because i doesn't exist here.
       }        
    """   

    FragmentShaders.append(f)

print("end of shads")


the rest of the code works perfectly, but I see no reason to put it here.
to my surprise the bge keeps glsl functions as strings until they're in use, but for some reason you can't use replace on them. Therefore if you want to share memory between a glsl shader and the bge you can do something like this below. worked great for me anyway.

for i in range(257):
    f = """        
        varying vec4 maps[256];
        void main()
       {
          gl_FragColor = maps[100];//this is not valid because i doesn't exist here.
       }        
    """   
    f=list(f)
    a=str(i)

    f[100:103]=a

    f="".join(f)    
    print('verify:',f[100],f[101],f[102])

    FragmentShaders.append(f)