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)
1 Answer 1
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))
Sign up to request clarification or add additional context in comments.
Comments
lang-py
players.append(PlayerLogic.PlayerLogic(i))import PlayerLogic?import PlayerLogicis importingPlayerLogic.py. To import the class, tryfrom PlayerLogic import PlayerLogicplayerlogicand the classPlayerLogic.