没有这样的文件或目录:"train_art_path"



我正在尝试使用Jupyter Notebook从文件路径读取文档,如下所示。

train_art_path = "/work/TEXT_SUMMARIZATION/train_dialogue.txt"
with open(train_art_path, 'r') as file:
a=file.readlines()
print(a)
print('n')

我得到以下问题:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
/tmp/ipykernel_79659/545421924.py in <module>
----> 1 with open(train_art_path, 'r') as file:
2     a=file.readlines()
3     print(a)
4     print('n')
FileNotFoundError: [Errno 2] No such file or directory: 'train_art_path'

或者,我试着像下面这样阅读文档。

with open('train_dialogue.txt', 'r') as file:
a=file.readlines()
print(a)
print('n')

你能帮我解决第一个吗?提前感谢。

您使用train_art_path作为变量,因此不应该在赋值后引用'。改变…

with open('train_art_path', 'r') as file:

with open(train_art_path, 'r') as file:

相关内容

  • 没有找到相关文章

最新更新