How can I check the current working directory in Jupyter?
When working in Jupyter Notebook, you can view the current working directory in two different ways.
Using the os module:
First, import the os module in Python. Next, use the getcwd() function to obtain the current working directory and store it in a variable. Finally, use the print() function to display this variable.
Here is an example code:
import oscurrent_path = os.getcwd()
print(current_path)
After running the above code, you will see the current working directory in the output.
2. Utilize the magic command %pwd:
In Jupyter Notebook, you can use the %pwd magic command to retrieve the current working directory. Simply input %pwd in a cell and run the cell to display the current working directory.
Here is an example of how it is used:
%pwd
After executing the above code, you will see the current working directory in the output.
You can easily view the current working directory to ensure you are working in the correct directory, regardless of the method you use.