0

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)
asked Aug 8, 2017 at 16:20
5
  • Is PlayerLogic in its own file? You may have to call it like players.append(PlayerLogic.PlayerLogic(i)) Commented Aug 8, 2017 at 16:22
  • But you import PlayerLogic? Commented Aug 8, 2017 at 16:22
  • 1
    import PlayerLogic is importing PlayerLogic.py. To import the class, try from PlayerLogic import PlayerLogic Commented Aug 8, 2017 at 16:22
  • ah! thank you so much, fixed it Commented Aug 8, 2017 at 16:23
  • Also - don't use capital letters in the name of a module! Call the module playerlogic and the class PlayerLogic. Commented Aug 8, 2017 at 16:23

1 Answer 1

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))
answered Aug 8, 2017 at 16:30
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.