I am just confusing that when I apply:
os.listdir("HW-3/data_sets/")
It works well! and list all the name of files under that directories.However, when I added an additional slash. In my mind, it should be fine.
os.listdir("/HW-3/data_sets/")
But it shows error message:
OSError: [Errno 2] No such file or directory: '/HW-3/data_sets'
It let me think about this program is so unstable. How can I let it work well even when user input '/HW-3/data_sets'
? Thanks in advance!
A leading slash in a path means an absolute path, or a path that starts at the root of your filesystem. No leading slash makes the path relative to your working directory (typically wherever you launched the script from).
Because of this, the initial slash results in a path that is semantically different from no leading slash, so you should not expect the script to behave the same way for those two paths.
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