![](/img/trans.png)
[英]How can I manage python search paths or references in Visual Studio for Python files which are not part of a solution?
[英]Visual Studio python reading files relative paths
我在Visual Studio中打開了一個python項目文件夾,然后運行getter.py
,其中包含以下代碼:
getter.py
with open('instruments.txt', 'r') as f:
instrument_list = f.read().splitlines()
我的文件夾樹如下:
proj
-downloaders
--getter.py
instruments.txt
signals.py
如上所示, getter.py
位於donwloaders
文件夾中。 為什么Visual Studio在沒有FileNotFoundError
情況下運行上述腳本? 請注意,當我移動instructions.txt
到downloaders
的文件夾,它拋出FileNotFoundError
。 我應該更改設置嗎?
確保將txt文件放置在python腳本目錄中,而不是python項目目錄中。
proj
-downloaders
--getter.py
--instruments.txt
signals.py
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.