Two previous answers here are correct, but both are a bit unclear. I'll show with some examples:
The code you show will work fine:
>>> gCharlie = "Global!"
>>>
>>> def foo():
... print(gCharlie)
...
>>> foo()
Global!
>>> print(gCharlie)
Global!
So that's not the problem at all. However, you can't assign global variables inside a function:
>>> gCharlie = "Global!"
>>> def foo():
... gCharlie = "Local!"
... print(gCharlie)
...
>>> foo()
Local!
>>> print(gCharlie)
Global!
As you see, the global variable gCharlie did not change. This is because you did not modify it, you created a new local variable, with the same name. And this is the cause of the error:
>>> gCharlie = "Global!"
>>> def foo():
... oldCharlie = gCharlie
... gCharlie = "Local!"
... print(gCharlie)
...
>>> foo()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in foo
UnboundLocalError: local variable 'gCharlie' referenced before assignment
The hint is in the error. It says local variable gCharlie. The problem is not the inability to access the global gCharlie, but that the local one hasn't been created yet.
The fix is to specify that you don't want to create a local variable, but that you want to modify the global one. You do this with the global keyword.
>>> gCharlie = "Global!"
>>> def foo():
... global gCharlie
... oldCharlie = gCharlie
... gCharlie = "Local!"
... print(gCharlie)
...
>>> foo()
Local!
>>> print(gCharlie)
Local!
As you see now, you modified the global variable.
That said, global variables are usually a bad idea. Avoid them. Try to pass in the variables as parameters instead.