Python では、なぜos.path.splitext
「.」を使用しているのですか? os.extsep
?の代わりに拡張セパレーターとして
4356 次
1 に答える
5
os.extsep
をインポートすることによって定義されos.path.extsep
ます。しかし、あなたは正しいです、に関係なく、os.path.splitext()
常にを使用します:.
os.path.extsep
os.py
(3.2.2)から:
from os.path import (curdir, pardir, sep, pathsep, defpath, extsep, altsep,
devnull)
からntpath.py
(になるos.path
)
extsep = '.'
[...]
def _get_dot(path):
if isinstance(path, bytes):
return b'.'
else:
return '.' # instead of return extsep! [Comment by me, not in source]
[...]
def splitext(p):
return genericpath._splitext(p, _get_sep(p), _get_altsep(p),
_get_dot(p))
また、からgenericpath.py
:
def _get_dot(path):
if isinstance(path, bytes):
return b'.'
else:
return '.'
os.path()
実際には、拡張セパレーターを 2 回定義します。
すぐには変更されないため、おそらく問題にはなりません (いずれにせよ、サポートされているすべてのプラットフォームで同じです)。しかし、ある意味では、DRY の原則に違反しています。
于 2011-09-16T14:03:50.190 に答える