Unable to access the files stored at /home/radheshyamkori4902/apple.txt using jupyter notebook in a program

Hi,
I am not able to access the file apple.txt stored at location
/home/radheshyamkori4902/apple.txt
when I try to run the below program from my jupyter notebook.
import re
hand = open(‘apple.txt’)
for line in hand:
line = line.rstrip()
if re.search(‘Apple:’, line):
print(line)

It gives following error

FileNotFoundError Traceback (most recent call last)
in
1 import re
----> 2 hand = open(‘apple.txt’)
3 for line in hand:
4 line = line.rstrip()
5 if re.search(‘Apple:’, line):

FileNotFoundError: [Errno 2] No such file or directory: ‘apple.txt’

Please help me as earlier I was able to access it and have run many programs, but now I am not able to access it

Thanks & Regards,
Radhe

If you run a command !pwd to see your current working directory, you will come to know that the notebook on the right is not running in your home directory.

So, to open a file from your home directory, either you can access like this:

hand = open(‘apple.txt’)

or using an absolute path: /home/$USER/apple.txt, for me it would look like:

hand = open('/home/sandeepgiri9034/apple.txt')

Hi Sandeep,
Thanks, for your reply. I will try as mentioned.

Thanks & Regards,
Radhe