Welcome to see my homepage and contact me
: NicholasYe’s Homepage.
Two lines to solve your python path problems in Vscode
-
Two lines like this:
import os, sys sys.path.append(os.getcwd())
-
Let me explain more clearly, assuming you have a project structured like this:
- Code
__init__.py
Main.py
- Component
__init__.py
get_time.py
- Dataset
__init__.py
deal_formula.py
- Code
-
If you want to import some functions in or classes
Main.py
fromget_time.py
ordeal_formula.py
, here is how we do:import os, sys sys.path.append(os.getcwd()) from Code.Component import get_now_time() # Import get_now_time() function from Dataset.deal_formula import Formula # Import Formula class