簡體   English   中英

Visual Studio Python讀取文件的相對路徑

[英]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.txtdownloaders的文件夾,它拋出FileNotFoundError 我應該更改設置嗎?

確保將txt文件放置在python腳本目錄中,而不是python項目目錄中。

proj
    -downloaders
        --getter.py
        --instruments.txt
    signals.py

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM