Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Classes with multiple attribute levels [Beginner]

Does python have a similar functionality with its data structure similar to what can be seen in MATLAB?

For example, being able to call a class similar to what follows:

variable = Class(inputs)

would allow to call variable with multiple attributes (not sure if attributes is the correct terminology here).

variable.attribute1.attribute2

In other words, defining a Class would provide the functionality of these multiple attributes. I am only seeking documentation if such functionality exists.

I'll add a little example because my question is quite vague. So, I'll define a class that assigns data sets to a variable.

class Properties(object):

    def __init__(self, data_set1, data_set2):
        self.Data1 = data_set1
        self.Data2 = data_set2

Now, I'll define a variable.

variable = Properties([1, 2, 3, 7], [3, 9, 2, 8])

Obviously now I can call variable with its individual data sets as:

variable.Data1
variable.Data2

What I desire is to have another Class that will be able to then define Statistical properties of the sets, such as:

variable.Data1.Maximum
variable.Data1.Minimum
variable.Data2.StandardDev
like image 977
Brad D Avatar asked Oct 28 '25 08:10

Brad D


1 Answers

class Attribute(object):
    pass

class MyClass(object):
    def __init__(self):
        self.attribute1 = Attribute()

variable = MyClass()
variable.attribute1.attribute2 = 5
like image 146
chepner Avatar answered Oct 29 '25 23:10

chepner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!