簡體   English   中英

通過 VS Code 終端運行 python 文件

[英]Running python file through VS Code terminal

我的問題是我無法在 VS Code 終端中運行 python 文件,除非我指定完整路徑。 然而,當我看到任何 python 教程時,只輸入了 python 文件名並且它可以工作。 有人可以幫我解決這個問題嗎?

這些文件需要位於您正在操作/或具有其他 Python 文件的同一文件夾中。

為此,您可以使用兩種方法:

第一的:

import os
pwd = os.getcwd()

# again, make sure you file is in the same directory. 

the_file = (pwd + "\\filename.xlsx") 

或其次,

#the below you can use wherever your file is and it will locate it. 
# you specify the full path using pathlib.path and:
pathlib.path(directory here without the file itself).joinpath(file name here).

暫無
暫無

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

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