Cannot import file from same directory

goose.mp4

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"

Samathingamajig

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.

edited at
0

Comments

0 comments
Login to comment

Related

Unable to import a function from file in same directory

How to import a file from the same directory in python?

GO: Unable to import a function from file in same directory

How to import python class file from same directory?

Import css file from same non-root directory

how do I import a file from the same parent directory in rust

PyCharm import file in the same directory

Cannot resolve import from index.ts from script located in same directory

Python: import file from sibling directory, where parent directory has the same name

How do I import a function from a file in a directory on the same 'level' as my current directory

Import file from lib directory?

Cannot import modules even though the are in the same directory as the file I am working in

vscode won't import file in the same directory

Can't import .sage file in same directory

python3 - import a file in the same directory

Import .dlls in same directory as file in Java

Not able to import a file which is present in same directory

How to import from both a python file in a folder and a file on the same directory being called?

cannot import package from one directory up

Cannot import python class from another directory

Java cannot import from child of parent directory

Cannot import module from source directory in pycharm

Julia: import contents from package in same directory

How to import from a module in the same directory?

import files from same directory in VSCode

cannot read file from a directory

Cannot import class file from Java project into another class file in the same project

Why I cannot import function from another py file in current directory?

Python cannot import one of two identical classes int the same directory