Regarding Reading Files topic in Python Topic number 102/134

<1>
In the below code chunk from reading files section of python-
with open("/cxldata/python_sample_file") as f:
s = “”
for line in f:
print(line)
s = s + line
print(s)

I want to understand the path “/cxldata/python_sample_file”. How to access this path?

PS: Even in Linux Tutorial, the similar path was used to check big.txt file using cat /cxldata/big.txt. I could not find this path when I am using ls in my root directory. Please suggest

<2> While I am using the similar code, I have to use “/home/…/mbox.txt” instead of “/mbox.txt” directly in the open statement otherwise it throws an File Not Found error, whereas you have used the “/cxldata/python_sample_file” directly.
with open("/home/niteshjindal20105879/cloudxlab_jupyter_notebooks/mbox.txt") as f:
for line in f:
print(line)

Please provide clarity on the above-stated paths.

A file path starting with The slash “/” means it is absolute.

Path: /cxldata/big.txt
Description:
The file big.txt exists inside a folder “cxldata” which is located at top-level directory. This is an example of absolute path.

Path: myfolder/myfile.txt
Description:
The file “myfile.txt” is existing inside a folder “myfolder” which should be in my present working directory. This is a relative path.

Please go thru the Linux tutorial to get more understanding of Linux file paths.

Thank you sir

Does the top level directory means root directory?

My understanding is that the directory where I work i.e. /home/niteshjindal20105879/cloudxlab_jupyter_notebooks is the root directory.

Is there a way that I can use ls command to check the files in the path /cxldata/python_sample_file using ls command?

yes. Thats right.

The environment that opens on the right side during course/project, it saves the files in this folder.

When you open Jupyter normally via “My Lab”, the folder that appears is your home directory i.e. /home/niteshjindal20105879

Yes. You can go to console and check using : ls /cxldata etc.

thanks …

1 Like