Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between sys and os.sys

Tags:

python

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() 
like image 995
Kracekumar Avatar asked Jun 28 '11 15:06

Kracekumar


People also ask

What is import os and sys?

It means your importing OS module in Python which provides a way of using operating system dependent functionality. Functions that the OS module provides allows you to interface with the. underlying operating system that Python is running on (Windows,Linux,Mac). cadman6735: import sys.

Does os module work on Mac?

Overview. The OS module in Python provides a way of using operating system dependent functionality. The functions that the OS module provides allows you to interface with the underlying operating system that Python is running on – be that Windows, Mac or Linux.

What is Python library os?

The OS module in Python provides functions for creating and removing a directory (folder), fetching its contents, changing and identifying the current directory, etc. You first need to import the os module to interact with the underlying operating system.

Why sys is used in Python?

The sys module in Python provides various functions and variables that are used to manipulate different parts of the Python runtime environment. It allows operating on the interpreter as it provides access to the variables and functions that interact strongly with the interpreter.


1 Answers

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.

like image 170
Ignacio Vazquez-Abrams Avatar answered Oct 02 '22 13:10

Ignacio Vazquez-Abrams