0
import Stock

Whenever I try to do this I get this error

ModuleNotFoundError: No module named 'Stock'

My Stock file is located in the same folder as stock_test (this is where I do import Stock) and I have an init file in the same folder.

I'm not really sure what I'm missing here, any help would be appreciated.

Stock file has everything that is working and I need it to import.

AS Mackay
  • 2,831
  • 9
  • 19
  • 25
Pharah181
  • 247
  • 1
  • 3
  • 7

1 Answers1

0

I make a folder based on your discription. Below is the structure.

├── Stock.py
├── Stock_sub
│   ├── Stock_test2.py
│   └── __init.py
├── Stock_test.py
└── __init__.py

For Stock.py,

def test():
    print('Stock.py is imported')

Now if you want to use test function in Stock_test.py, because they are in the same folder, you can import Stock just by

import Stock
Stock.test()

If you want to use Stock.py in Stock_test2.py, because they are in the different folder, so you need to specify the search path of import package

import sys
sys.path.append('../')

import Stock
Stock.test()

I use function here, the same if you want to import Class.

milkice
  • 455
  • 6
  • 10