[英]VS code do not recognise relative path as filename
I have the following folder structure我有以下文件夹结构
---data/
|-----test.csv
---pythonscript/
|-----myscript.ipynb
|-----myscript.py
The following codes work just fine in myscript.ipynb
:以下代码在
myscript.ipynb
中运行良好:
import pandas as pd
df1=pd.read_csv('../data/test.csv')
However, when I moved the same codes to myscript.py
and run it using VS code, it shows me the FileNotFoundError
that '../data/test.csv'
does not exist.但是,当我将相同的代码移动到
myscript.py
并使用 VS 代码运行它时,它会显示FileNotFoundError
'../data/test.csv'
不存在。 I checked:我检查了:
pythonscript/
pythonscript/
相同的 cwdtest.csv
on VScode instead, it works also fine.test.csv
上使用 test.csv 的绝对路径时,它也可以正常工作。 Because I are sharing the codes with a peer, I want to avoid typing absolute path as possible.因为我与同行共享代码,所以我想尽可能避免输入绝对路径。
The temporary solution I came up with, is to have additionally:我想出的临时解决方案是另外:
import os
os.chdir("..")
f1=os.getcwd()+'/data/'
df1=pd.read_csv(f1+'test.csv')
But it is not really succinct.但这并不简洁。 I wonder if there is a standard solution for this kind of annoyance in VS code?
我想知道是否有针对 VS 代码中这种烦恼的标准解决方案? I am very new to VS code.
我对 VS 代码很陌生。 Thanks!
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.