I'm using VS Code with the following steps:
cd into my Dev foldermy_projects folderNow inside the my_projects folder, it's the root workspace directory and I can navigate to the following folders/files:
my_projects/
        > DBHelper
            > dbhelper.py
            > config.ini
        > PortfolioManagement
        > Learning
Now when I run dbhelper.py, I tried the following test:
import os
print(os.getcwd())
I get the following:
my_projects
But I'm expecting
my_projects/DBHelper/
How do I get Code Runner in VS Code to recognize that the file that I'm currently in, which in this case dbhelper.py is in the current working directory?
The reason I ask is because I created a Database class using postgres and whenever I use dbhelper in different folders, it's not recognizing the config.ini file I have in that directory.
I figured it out. In my VS Code settings, I added these settings:
{
    "python.pythonPath": "/Users/anaconda/bin/python",
    "code-runner.executorMap": 
    { 
        "python": "$pythonPath -u $fullFileName" 
    },
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true,
    "python.terminal.executeInFileDir": true,
    "code-runner.fileDirectoryAsCwd": true
}
I went to the Code Runner settings from the Extensions listing from the VS Code GUI. I found a setting 'Code-runner: File Directory as CWD' and set that on. That fixed my issue, not sure if that was what the JSON above does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With