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 repl.it. 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 (77) [earned 5 cycles]
View Answer
Commentshotnewtop
JoshDaBosh (77)

use

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

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

21natzil (972)

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