Elegant way to take basename of directory in Python?

后端 未结 5 1351
傲寒
傲寒 2021-02-20 01:30

I have several scripts that take as input a directory name, and my program creates files in those directories. Sometimes I want to take the basename of a directory given to the

5条回答
  •  粉色の甜心
    2021-02-20 02:06

    to build the paths without writing slashes it is better to use:

    os.path.join(dir, subdir, file)
    

    if you want to add separators or get the separator independly of the os, then use

     os.sep
    

提交回复
热议问题