I have recently read about dirname
and basename
. My book uses the following image to explain the difference between them:
I am currently using OSX so my root folder will be /. I wrote the following code in my shell:
path='\\Users\\apple\\Documents\\list.txt'
os.path.dirname(path)
The result that I got was: ''
Then I wrote the following code to check the basename:
os.path.basename(path)
and the result that I got this time was: '\\Users\\apple\\Documents\\list.txt
!
Whats happening over here? How to fix it?
Also, I don't have any text file whose name is list. Shouldn't this cause an error when I was trying to find the dirname
and basename
of a file that does not exist!?