S.Lott is right: the OP's code works.
It works either with the_parameter defined before the class's definition or after, it doesn't matter.
What happens is that when the function my_func is called as a method of one of the instances, the object the_parameter is searched in the environment of the my_func's code block, that is to say: first in the local scope of the function, then outside the function, until the global namespace (= module level), because "When a name is used in a code block, it is resolved using the nearest enclosing scope." (ref)
So there's no need to find a solution to a problem that doesn't exist.
.
However, this code can be improved IMO, because, as it is, it implies that the_parameter must be found among all the objects binded at the global level, and these objects are possibly very numerous.
Defining global the_parameter
inside the function's code shortens the process of research: the execution will go directly at the global level to search the object, without exploring the function's namespace.
But anyway, in these two cases, it is a poor process, contrary to the the purpose of classses, as underlined by jena : an instance must be a self-sufficient object having fields that provide all that is necessary to its functionning.
.
The solution of jena isn't the best yet, because it implies that the_parameter must be passed as argument each time an instance will be created.
If the_parameter is intended to be invariably common to all the instances of MyClass, the code should make it a more strictly associated object to all the instances of MyClass.
So it seems to me that the following code is the more convenient:
class MyClass(object):
import ConfigParser
config = ConfigParser.ConfigParser()
config.read('config.cfg')
the_parameter = config.getint('my_section','the_parameter')
del ConfigParser,config
def my_func(self):
print('the_parameter == ' + str(MyClass.the_parameter))
Doing so, the search of the_parameter will be done by exploring the namespace of the class, not in the vast global namespace.
.
Update
Well, I realize that to find MyClass.the_parameter , the execution must first search the object MyClass in the global namespace, and that anihilates what I pretended.
To avoid the search in the global namespace, the call to the _class_ attribute of the instance must be done like that:
def my_func(self):
print('the_parameter == ' + str(self.__class__.the_parameter))