Ask coding questions

← Back to all posts
Classes in separate files (Python 3)
DanielNorthcott (0)

How to I use a class that is not in my main file on The class' name is Player
import Player - does not work
Console: ModuleNotFoundError: No module named 'Player'
human = Player("Human") - Does not work too if i don't import
Console: NameError: name 'Player' is not defined

Thank you for the help :D

Answered by JoshDaBosh (79) [earned 5 cycles]
View Answer
JoshDaBosh (79)


from {fileName[:-2]} import {className}
HappyFakeboulde (236)

you use import with the filename of the file that contains Player, without the .py

21natzil (1163)

Could you please include the file you're having issues with?