Kracekumar
Kracekumar

Reputation: 20419

What is the difference between sys and os.sys

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.

I often see code using sys.exit like this, rather than using os.sys.exit, but both do the same thing.

import os   
import sys    
sys.exit()

Upvotes: 27

Views: 16744

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799150

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.

Upvotes: 35

Related Questions