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

折月煮酒 提交于 2019-12-06 00:46:06

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.

Easy confusing is lies in the case: os.open("something"), open("something") and sys.open("something").

A "mnemonic" is the documentation, available on-line or downloaded to your workstation.

The "mnemonic" is easy. Use the one that matches your requirements.

why they were created with their current names

To keep clutter out of the language an in separate libraries.

Are naming due to things like having FDs in a class?

Probably. FD's are an OS feature, not a language feature. That's why they're in a separate library.

Is naming because some classes require special privileges?

Not at all.

To which extent is the naming a design solution?

To keep clutter out of the language an in separate libraries.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!