Python os.listdir () No such file or directory

I'm just confused that when I apply:

os.listdir("HW-3/data_sets/")

It works well! and list all the file names under these directories. However, when I added an extra slash. In my opinion, everything should be fine.

os.listdir("/HW-3/data_sets/")

But it shows an error message:

OSError: [Errno 2] No such file or directory: '/HW-3/data_sets'

This allowed me to think that this program is so unstable. How can I let it work well even when the user types '/HW-3/data_sets'? Thanks in advance!

+4
source share
1 answer

, . ( , script).

- , , , , script .

+5

All Articles