I'm new to Python, and currently using the os module. I came across a doubt.
Can anyone explain me, what is the difference between the following lines?
os.mkdir('dir_name')
os.mkdir('/dir_name')
The former creates the folder in the current directory but what about the later? There's no folder created in the current directory, where is it created then?
os.mkdir('dir_name') # relative
The first path is relative. The first code line will make a directory "dir_name" in the current working directory. It is relative because the path will change relative to the working directory.
os.mkdir('/dir_name') # absolute
This second path is absolute. "/" refers the the operating system's root directory. The second code snippet will make a "dir_name" directory in the root directory. The path is absolute because unlike the "current working directory", the root directory will never change.
Consider os.mkdir('../dir_name') for full picture. It is also a relative, but uses .. to denote upper level folder, relative to current one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With