I’m trying to import functions located in a Python file outside of my Visual Studio Code workspace. Let’s say my structure is:
folder/
├── workspace/
│ └── main.py
│
└── python_scripts/
└── utils
└── __init__.py
└── functions.py
And let’s say from main.py I want to be able to call the list_files() function present in functions.py (of course I could put this file in my current workspace, but these are utility functions I want to share across many different projects). After (a lot!) of searching and tweaking, I was able to make it work using:
#main.py
sys.path.append('C:\folder\python_scripts')
from utils import *
list_files()
This script runs without any issues (inside __init__.py
there is also some code to add all functions from functions.py to the global name space). However, Visual Studio Code underlines the function list_files()
with a warning saying “list_files” is not defined.
Any idea why, and does it mean I messed up (again!) with the import process, even though the script runs?