Search code examples
pythonsecurityoperating-systemnaminglanguage-history

Reasons behind naming in easy-to-confuse Python's classes such as OS and SYS?


I have noticed that considerably amount of questions in SO, relating to Python, are about people messing up Sys -class, OS class and no class. For example, an easy confusing is the case: os.open("something"), open("something") and sys.open("something"). I haven't understood yet the reasons behind the naming of classes, perhaps it is just an evolution.

  1. I would like to hear why they were created with their current names?
  2. Are naming due to things like having FDs in a class?
  3. Is naming because some classes require special privileges?
  4. To which extent is the naming a design solution?

If you cannot answer the question, feel free to suggest some good mnemonics to memorize the classes and to differentiate them.


Solution

  • Built-in functions are things that you need often. You do not have to import any module to access them, and thus don't use any module prefix either. open() is one such function, since opening files is a very common operation. It opens a file and returns a file object, which is easy to use.

    The os module is for operating system interfaces. os.open() is a raw interface to the file interface of the operating system. It opens a file and returns the bare file descriptor, which you do not normally need for anything.

    The sys module is for system-specific things. sys.open() does not exist.