Elegant way to take basename of directory in Python?

后端 未结 5 1272
傲寒
傲寒 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:09

    Manually building up paths is a bad idea for portability; it will break on Windows. You should use os.path.sep.

    As for your first question, using os.path.join is the right idea.

提交回复
热议问题