What's the best way to add a trailing slash to a pathlib directory?

前端 未结 3 2120
囚心锁ツ
囚心锁ツ 2021-02-14 10:20

I have a directory I\'d like to print out with a trailing slash: my_path = pathlib.Path(\'abc/def\')

Is there a nicer way of doing this than os.path.j

3条回答
  •  执笔经年
    2021-02-14 10:55

    You could also use:

    os.path.normpath(str(my_path)) + os.sep
    

    I would say it is down to preference rather than being "nicer"

提交回复
热议问题