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.
why
they were created with their current names? If you cannot answer the question, feel free to suggest some good mnemonics to memorize the classes and to differentiate them.
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.