Saba
Saba

Reputation: 79

How to define attribution of attribution in python

I am trying to make an attribution of an attribution in python. Is there a way to do so:

  class Foo():
     def __init__(self, x, y):
         self.x = x
         self.x.y = y

I have no idea how to do it, I checked for some examples. But I have not found any example similar.

Upvotes: 1

Views: 619

Answers (1)

Radek Hofman
Radek Hofman

Reputation: 527

Not exactly clear what you need you can do something like this (for example):

class Bar(object):
    def __init__(self, y=None):
       self.y = y

class Foo(object):
    def __init__(self, x, y):
       self.x = x
       self.x.y = y

if __name__ == '__main__':
     x = Bar()
     y = 1
     foo = Foo(x,y)

Upvotes: 1

Related Questions