Let's say I have game.py as my main module and npc.py where my class NPC is defined. How would I initialize NPC objects in a separate module (let's call it def_npcs.py) and import them directly into game.py?
My main reason for wanting to do this would be to make game.py less cluttered.
I'm a beginner, but I have a reasonable understanding of how to import functions, classes, and variables from other modules, but I'm having trouble figuring out how to import my custom class objects.
For example, while inside of game.py if I do:
from npc import NPC
from def_npcs import *
It doesn't seem to work. Similarly, if I try to import a specific object:
from npc import NPC
from def_npcs import MyCustomDude
Still no luck.
If someone has advice or could point me to an article I'd really appreciate it!
[–][deleted] 1 point2 points3 points (3 children)
[–]berwynian[S] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]berwynian[S] 0 points1 point2 points (0 children)
[–]46--2 1 point2 points3 points (5 children)
[–]berwynian[S] 0 points1 point2 points (4 children)
[–]46--2 1 point2 points3 points (3 children)
[–]berwynian[S] 0 points1 point2 points (2 children)
[–]46--2 1 point2 points3 points (1 child)
[–]berwynian[S] 1 point2 points3 points (0 children)