Accessing an instance of a class from within instance of another class
krastanov.stefan at gmail.com
Fri Apr 30 07:05:43 EDT 2010
I have some knowledge of programing in C++ and I believe that I understand
the way one should write programs in Python. But I need some help finding
the Right Way for doing a thing.
Here is the problem:
I have a class (call it Data) that has a number of NumPy arrays and some
methods that get useful information from the arrays (math stuff).
I have two other classes (called Viewer1 and Viewer2) (they are subclasses
of QAbstractTableModel but that's not important).
I am working in my code with one instance of each class. Viewer1 and Viewer2
must be able to call methods from the Data instance, but as the instance of
Data is constantly updated, I cannot just copy it.
I have thought of the following solution:
data = Data()
def __init__(self, ***, data):
self.D = [data, ]
It's an ugly way to implement a pointer or something like it. What is the
P.S. Maybe it's bad idea to use two different view classes, but that is
P.P.S. Maybe I'm breaking the encapsulation. What should I do?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list