What is the difference between sys
and os.sys
in python? I have seen many projects using sys
when they have imported os
. When I tried dir(sys)
and dir(os.sys)
they had same functions and their output was same.
python中sys和os.sys有什么区别?我已经看到很多项目在导入os时使用sys。当我尝试dir(sys)和dir(os.sys)时,它们具有相同的功能,并且它们的输出相同。
I often see code using sys.exit
like this, rather than using os.sys.exit
, but both do the same thing.
我经常看到像这样使用sys.exit的代码,而不是使用os.sys.exit,但两者都做同样的事情。
import os
import sys
sys.exit()
1 个解决方案
#1
28
os.sys
is os
's "private" name for sys
; Python does not hide imports performed in another module. You should not depend on its existence, and should instead import sys
directly yourself.
os.sys是os的sys的“私有”名称; Python不会隐藏在另一个模块中执行的导入。你不应该依赖它的存在,而应该自己直接导入sys。
#1
28
os.sys
is os
's "private" name for sys
; Python does not hide imports performed in another module. You should not depend on its existence, and should instead import sys
directly yourself.
os.sys是os的sys的“私有”名称; Python不会隐藏在另一个模块中执行的导入。你不应该依赖它的存在,而应该自己直接导入sys。