'Python have a class variable defined as an instance inside another class [closed]
I am looking to have a class variable inside another class. Class A is what I want to have as an instance in class B. Somehow I get an error:
new_B = B("Hello", new_A) TypeError: B() takes no arguments
I have read something about inner classes but don't understand how to apply constructors there.
class A:
hp_id = ""
def __init__(self, hp_id):
self.hp_id = hp_id
class B:
score = ""
strand = A()
def __int__(self, score, strand):
self.score = score
self.strand = strand
new_A = A("hello")
new_B = B("Hello", new_A)
print(new_B)
Solution 1:[1]
Error is because you misspelled your B's constructor __int__
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
