Reputation: 13
I know this question has been posted alot, however I cannot get my code to work. I have 2 classes, Main and PlayerLogic. I want to create multiple PlayerLogic objects within a loop, however I am getting this error "TypeError: 'module' object is not callable"
EDIT: I didnt mention that the classes are in different files with the exact same name of the class
class Main:
import PlayerLogic
numPlayers = int(input("How many player would you like? [excluding you]"))
players = []
for i in range(numPlayers):
players.append(PlayerLogic(i))
class PlayerLogic:
import random
def __init__(self,name):
self.name = str(name)
Upvotes: 0
Views: 1926
Reputation: 951
Your import is just importing the module not the PlayerLogic class.
You could do:
from PlayerLogic import PlayerLogic
Or keep the import as it is but then inside the loop use:
players.append(PlayerLogic.PlayerLogic(i))
Upvotes: 1