[Tutor] Accessing class instances
stevege at i-way.net.uk
Wed Mar 17 06:40:18 EST 2004
I'm having a bit of a problem understanding how to use modules and
The basic idea in my program is to have a number of classes as follows:
"" Does all my start-up stuff and controls it """
""" parses options and stores them as attributes"""
""" Loads a data file and allows operations on it """
I put MainProgram() and Options() classes into one single text file and
my DataLoader() class into another.
When I instantiate my DataLoader object I want it to look at the
instance of my Options() class and pull some information from it. At
the moment I get:
NameError: global name 'Opts' is not defined
I think I have two problems going on:
a. I don't think I understand how a class can query an instance of a
So here my DataLoader class when it's instantiated needs to query an
instance of my Options() class named Opts.
At the moment I understand how one module can access another and
instantiate an object e.g. DataLoader.dataloader() but I'm less clear
how a module can access the instance of that class at runtime.
b. Have I mis-used modules?
I used the different files/modules thinking that it logically separated
how I was thinking about the problem. Howerver, there is some
information I need to pass back and forward between them, the use of
'options' is a good example. How do Python programmers normally get
Hope I've been clear in my explanation!
More information about the Tutor