I am trying to read documents from a file path using a Jupyter Notebook as follows.
train_art_path = "/work/TEXT_SUMMARIZATION/train_dialogue.txt"
with open(train_art_path, 'r') as file:
a=file.readlines()
print(a)
print('\n')
I get the following issue:
---------------------------------------------------------------------------
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'
Alternatively, I tried to read documents as follows. It works perfectly.
with open('train_dialogue.txt', 'r') as file:
a=file.readlines()
print(a)
print('\n')
Can you please help me to solve the first one? Thanks in Advance.
CodePudding user response:
You are using train_art_path
as a variable, so should not have quotes '
after assignment. Change...
with open('train_art_path', 'r') as file:
to
with open(train_art_path, 'r') as file: