Tyler Rainey
Tyler Rainey

Reputation: 1

Put class on class

how would I go about doing the pseudo code below

import bClass
import cClass

class aClass:
    def __init__(self):
        pass

a = aClass()
a.bClass = bClass()
a.cClass = cClass()

How would I put these classes on this parent class? When I try I get

p.GlobalHistory = GlobalHistory()
TypeError: 'module' object is not callable

Thanks,

Upvotes: 0

Views: 34

Answers (1)

joanis
joanis

Reputation: 12229

I assume you've defined class bClass in bClass.py, and class cClass in cClass.py. What you've imported are the modules, not the classes themselves. The classes are then bClass.bClass, i.e., name bClass inside module bClass.

You can access the class like this:

a.bClass = bClass.bClass()

or change your import like this:

from bClass import bClass
a.bClass = bClass()

Upvotes: 2

Related Questions