Benefits of os.path.splitext over regular .split?

前端 未结 11 966
独厮守ぢ
独厮守ぢ 2020-12-08 13:16

In this other question, the votes clearly show that the os.path.splitext function is preferred over the simple .split(\'.\')[-1] string manipulatio

11条回答
  •  鱼传尺愫
    2020-12-08 13:47

    The first and most obvious difference is that the split call has no logic in it to default when there is no extension.

    This can also be accomplished by a regex, in order to get it to behave as a 1 liner without extra includes, but still return, empty string if the extension isn't there.

    Also, the path library can handle different contexts for paths having different seperators for folders.

提交回复
热议问题