如何让 VS 代码中的 codeRunner 识别我当前的工作目录? [英] How to make codeRunner in VS code recognize my current working directory?

查看:24
本文介绍了如何让 VS 代码中的 codeRunner 识别我当前的工作目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近下载了 VSCode.我在做一些开发工作.通常我会执行以下步骤:1) cd 进入我的 Dev 文件夹2) 然后编码 my_projects

I recently downloaded VSCode. Im doing some development work. Usually I do the following steps: 1) cd into my Dev folder 2) then code my_projects

现在在 my_projects 文件夹中,它是根工作区目录.我打开了 VS 代码,可以导航到以下文件夹/文件:

Now inside my_projects folder, its the root workspace directory. I have my VS code opened, and can navigate to following folders/files:

my_projects/
        > DBHelper
            > dbhelper.py
            > config.ini
        > PortfolioManagement
        > Learning

现在,当我打开 dbhelper.py 时,我尝试了以下测试:导入操作系统打印(os.getcwd())

Now when i open dbhelper.py, I tried the following test: import os print(os.getcwd())

我得到以下信息:

my_projects

但我很期待

my_projects/DBHelper/

如何让 VSCode 中的 codeRunner 识别我当前所在的文件,在这种情况下,dbhelper.py 是当前工作目录?

How do I get codeRunner in VSCode to recognize the file that im currently in, in this case dbhelper.py is the current working directory?

我问的原因是因为我使用 postgres 创建了一个数据库类来帮助我进行一些个人研究,并且每当我在不同的文件夹中使用 dbhelper 时,它都无法识别该目录中的 config.ini 文件.

The reason I ask is because i created a Database class using postgres to help me with some personal research and wheneever i use dbhelper in different folders, its not recognizing the config.ini file I have in that directory.

谢谢

推荐答案

我想通了.在我的 VScode 设置中,我添加了以下内容:

I figured it out. In my VScode settings, i added this:

{
"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

}

这篇关于如何让 VS 代码中的 codeRunner 识别我当前的工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆