Trying to import a file (meleeWeapons.py
) into my main file (main.py
) but it does not seem to be working.
The file directy is as follows
Domination
|_main.py
|_meleeWeapons.py
|_test.py
When I load from Domination import meleeWeapons
or from . import meleeWeapons
into main.py, trying to load any objects from meleeWeapons into main doesnt work, flagging "myObject" is not defined
. When I do the from Domination import meleeWeapons
approach, the error "Import "Dominations" could not be resolved"
When you import things from a local module, you put the module name first, then the symbols ("objects") second
from meleeWeapons import Domination
If you want to import everything into the global namespace (you rarely, if ever, want to do this), then do this:
from meleeWeapons import *
If you want import the module itself, and using meleeWeapons.Dominion
to access Dominion
(or any other symbol), then just do a standard import:
import meleeWeapons
You can also give the module an alias:
import meleeWeapons as mW
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments